C Language: Several forms of pointers

Source: Internet
Author: User

Two forms of the string:

1, character arraychar name[32] = "Zhangsan";//can only be done at initialization timestrcpy (name, "Lisi");//Overall assignment can only be done by strcpyname = "Lisi";//error, assigns the address of a constant string ("Lisi") to the constant pointer (char* const name)2. Character Pointerchar *name = "Zhangsan";//pointer variable name points to the start address of a constant stringchar* name;//using wild pointers (uninitialized pointers)scanf ("%s", name);//error,strcpy (name, "Lisi");//error, if name points to a constant string, it will collapse. If name is not initialized, it is possible for the program to collapse and potentially overwrite the data in memory. name = "Lisi";//ok, re-modifies the pointer variable name to point to a new string address.  1, const int* p and int const* p: The meaning of the two is the same. The point is read-only data and cannot be changed by Q, but the address pointed to can be changed.  2, int* const P: The pointer must first be initialized, and the point of the address is read-only, can not be changed again, but the point of the content can be changed.  3. Const int* Const P: You can neither change the address pointed to by the pointer, nor change the content that the pointer points to.

C Language: Several forms of pointers

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.