Strings defined using array and pointer notation - C++ Data Type

C++ examples for Data Type:char array

Description

Strings defined using array and pointer notation

Demo Code

#include <iostream>
using namespace std;
int main()/*w w w .j a  v a  2 s  .co  m*/
{
   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;
}

Result


Related Tutorials