C++ char array defined using array and pointer notation

Description

C++ char array defined using array and pointer notation

#include <iostream>
using namespace std;
int main()/*from  w  ww .  j  av  a 2s .c  om*/
{
   char str1[] = "Defined as an array";
   char* str2 = "Defined as a pointer";
   cout << str1 << endl;    // display both strings
   cout << str2 << endl;
   // str1++;                  // can't do this; str1 is a constant
   str2++;                  // this is OK, str2 is a pointer
   cout << str2 << endl;    // now str2 starts "efined..."
   return 0;
}



PreviousNext

Related