C++ char array Prints strings and characters
#include <iostream> using namespace std; void main()/*ww w . j a va2 s. c o m*/ { char names[]={'T','e','d','\0','E','v','a','\0', 'S', 'a','m','\0'}; // Must use extra percent (%) to print %s and %c. cout << "names " << names << "\n"; cout << "names+0 " << names+0 << "\n"; cout << "names+1 " << names+1 << "\n"; cout << "names+2 " << names+2 << "\n"; cout << "names+3 " << names+3 << "\n"; cout << "names+5 " << names+5 << "\n"; cout << "names+8 " << names+8 << "\n\n"; cout << "(names+0)[0] " << (names+0)[0] << "\n"; cout << "(names+0)[1] " << (names+0)[1] << "\n"; cout << "(names+0)[2] " << (names+0)[2] << "\n"; cout << "(names+0)[3] " << (names+0)[3] << "\n"; cout << "(names+0)[4] " << (names+0)[4] << "\n"; cout << "(names+0)[5] " << (names+0)[5] << "\n\n"; cout << "(names+2)[0] " << (names+2)[0] << "\n"; cout << "(names+2)[1] " << (names+2)[1] << "\n"; cout << "(names+1)[4] " << (names+1)[4] << "\n\n"; return; }