Prints strings and characters from a character array. - C++ Data Type

C++ examples for Data Type:char array

Description

Prints strings and characters from a character array.

Demo Code

#include <iostream>
using namespace std;
void main()// w ww. ja  va  2s. co  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;
}

Result


Related Tutorials