C ++ String constant and String constant

Source: Internet
Author: User

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:

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.