- int x, y;
- int * const ptr = &x; //ptr is a constant pointer to an integer
- //An Integer can be modified through ptr,
- //but ptr always points to the same memory
- //location.
- *ptr = 7; //correct
- ptr = &y; //Error
- int x=5, y;
- const int *const ptr = &x; //ptr is a constant pointer to a
- //constant integer. ptr always
- //points to the same location
- //and the integer at that location
- //cannot be modified.