C + + string constants
When a string constant appears in an expression, its value is a pointer constant. The compiler stores a copy of the specified character in a location in memory (the global Zone) and stores a pointer to the first character. However, when the array name is used in an expression, their values are also pointer constants. We can do subscript references, indirect access, and pointer operations on them.
#include <iostream>using namespacestd;intMain () {/*when a string constant appears in an expression, its value is a pointer constant. The compiler stores a copy of the specified character in a location in memory and stores a pointer to the first character. However, when the array name is used in an expression, their values are also pointer constants. We can do subscript references, indirect access, and pointer operations on them. */cout<< *"XYZ"<< Endl;//xcout << *"XYZ"+1<< Endl;//ASCLL code for ycout <<"XYZ"[2] << Endl;//Z//cout << * ("xyz" +4) << Endl;cout <<"XYZ"+1<< Endl;//YZ /*====== equivalent to ======*/cout<<"/*====== equivalent to ======*/"<<Endl; Char*p="XYZ"; cout<< *p << Endl;//xcout << *p+1<< Endl;//ASCLL code for ycout <<Char(*p+1) << Endl;//ycout << p[2] << Endl;//Zcout << p+1<< Endl;//YZ return 0;}
Operation Result:
C + + string constants