C ++ String constant and String constant
C ++ String constant
When a String constant appears in an expression, its value is a pointer constant. The compiler stores a copy of the specified character at a location in the memory (global), and stores a pointer pointing to the first character. However, when array names are used in expressions, their values are also pointer constants. We can reference them with subscripts, perform indirect access, and perform pointer operations.
# Include <iostream> using namespace std; int main () {/* When a String constant appears in an expression, its value is a pointer constant. The compiler stores a copy of the specified character at a location in the memory and stores a pointer pointing to the first character. However, when array names are used in expressions, their values are also pointer constants. We can reference them with subscripts, perform indirect access, and perform pointer operations. */Cout <* "xyz" <endl; // x cout <* "xyz" + 1 <endl; // y's ascll code cout <"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; // x cout <* p + 1 <endl; // y's ascll code cout <char (* p + 1) <endl; // y cout <p [2] <endl; // z cout <p + 1 <endl; // yz return 0 ;}
Running result: