Mega Code Archive

 
Categories / C Tutorial / Pointer
 

Attempting to modify data through a non-constant pointer to constant data

xPtr cannot be used to modify the value of the variable to which it points. #include <stdio.h> void f( const int *xPtr ); int main() {    int y;           f( &y );         return 0;     } void f( const int *xPtr ) {    //*xPtr = 100;  /* error: cannot modify a const object */ }