// The const keyword has a number of interactions with // pointer and reference declarations, depending on the placement // of the const. In fact, more than one const can appear in such // a declaration! #include main() { // Case 0: no const // Our old friend the pointer to a character char * p0 = "A simple string"; // Case 1: pointer to a const char // We can change the pointer, but not what it points to const char * p1 = "A pointer to const char"; // This is legal p1++; // This is not p1[2] = 'x'; // But we can't change the pointer itself char * const p2 ="This is a constant pointer"; // We can modify what p2 points to // This is legal p2[2] = 'u'; // Changes the 'i' to a 'u'. // Case 2: A constant pointer to a char // This is not legal p2++; // Case 3: A constant pointer to a constant char // We can't change either q or *q const char * const p3 = "A constant pointer to a constant"; // Neither of these is legal p3[2] = 'u'; p3++; }