String str Initializes a str to a character array and a character array.

Source: Internet
Author: User

C and Pointers ("pointers on C") 8.1.11

A string, such as "Hello", is usually a string constant that can be used to assign a value to a character pointer, or to initialize it, equivalent to assigning the first address of the string constant to the pointer, such as:

char *p = "Hello";

Or

Char *p;

p= "Hello";

string of C++stl

String constants cannot write to read

However, when using "Hello" to initialize a character array, "Hello" is not a string constant, but rather an initialization list {' H ', ' e ', ' l ', ' l ', ' o ', ' s '}, at any other time, it represents a string constant. The array name is also a pointer constant, and you cannot assign a value to a constant. So

Char a[] = "Hello"; Correct, hello ", not a string constant, but equivalent to an initialization list

and

Char a[6];

A = "Hello"; Error,A is a pointer constant, cannot be modified, and certainly cannot be assigned a value

String str Initializes a str to a character array and a character array.

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.