C++ char array Increments a pointer through a character array

Description

C++ char array Increments a pointer through a character array

#include <iostream>
using namespace std;
void main()//  w  w w .  j  a v  a2  s .  c  o  m
{
   char cara[] = {'a', 'b', 'c', 'd', 'e'};
   char *cp = cara;             // The pointers point to the start of the array.
   cout << *cp << "\n";
   cp++;                           // One is actually added.
   cout << *cp << "\n";
   cp++;                           // One is actually added.
   cout << *cp << "\n";
   cp++;                           // One is actually added.
   cout << *cp << "\n";
   cp++;                           // One is actually added.
   cout << *cp << "\n\n";
   cout << "The character size is " << sizeof(char);
   cout << " byte on this machine\n";
   return;
}



PreviousNext

Related