// Printing a string one character at a time using // a constant pointer to constant data -- must // use array subscript notation #include void printCharacters(const char * const); main() { char string[] = "print characters of a string"; cout << "The string is:" << endl; printCharacters(string); cout << endl; return 0; } // In printCharacters, sPtr is a constant pointer // to a character constant. // Characters cannot be modified through sPtr // (i.e., sPtr is a "read-only" pointer). // Must use array subscript notation to access elements. // sPtr is just like a regular array name! void printCharacters(const char * const sPtr) { int i; for (i = 0; sPtr[i] != '\0'; i++) // no initialization cout << sPtr[i]; }