Attempting to modify data through a non-constant pointer to constant data. : const pointer « Pointer « C Tutorial






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 */
}








10.9.const pointer
10.9.1.Attempting to modify a constant pointer to non-constant data
10.9.2.Attempting to modify data through a non-constant pointer to constant data.
10.9.3.Using a non-constant pointer to non-constant data
10.9.4.A non-constant pointer to constant data