C + + string constants

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.