Attempting to modify data through a nonconstant pointer to constant data. - C++ Data Type

C++ examples for Data Type:const

Description

Attempting to modify data through a nonconstant pointer to constant data.

Demo Code

void f( const int * ); // prototype 

int main() /*www  .  j ava2  s  . c o m*/
{ 
    int y; 

    f( &y ); // f attempts illegal modification 
}

// xPtr cannot modify the value of constant variable to which it points 
void f( const int *xPtr ) 
{ 
  //  *xPtr = 100; // error: cannot modify a const object 
}

Related Tutorials