Increments a pointer through a character array. - C++ Data Type

C++ examples for Data Type:Array Pointer

Description

Increments a pointer through a character array.

Demo Code

#include <iostream>
using namespace std;
void main()/*from   w ww  .  j ava2  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;
}

Result


Related Tutorials