C language: several forms of pointers, several types of C language pointers

Source: Internet
Author: User

C language: several forms of pointers, several types of C language pointers

Two types of strings:

1. character array char name [32] = "zhangsan"; // strcpy (name, "lisi") can only be performed during initialization "); // The overall value can only be assigned through strcpy name = "lisi"; // error, assign the address of a constant string ("lisi") to the constant pointer (char * const name) 2. Character pointer char * name = "zhangsan"; // the pointer variable name points to the starting address of the constant string char * name; // use a wild pointer (uninitialized pointer) scanf ("% s", name); // error, strcpy (name, "lisi"); // error. If the name points to a constant string, it will collapse. If the name is not initialized, the program may collapse or overwrite the data in the memory. Name = "lisi"; // OK. Modify the pointer to a new string address. 1. const int * p and int const * p: they have the same meaning. The content to be directed to is read-only data. q cannot be changed, but the address to be directed can be changed. 2. int * const p: the pointer must be initialized first, and the address to which the pointer is directed is read-only and cannot be changed. However, the content to which the pointer is directed can be changed. 3. const int * const p: neither the address or content pointed to by the pointer can be changed.

Related Article

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.