The "C language" pointer is a variable

Source: Internet
Author: User

1) pointer is a variable, is used to store the address of the variable, occupy memory space, used to save memory address;

2) When the pointer is declared, the * number indicates that the variable being declared is a pointer

When the pointer is in use, the * number represents the value in the memory space pointed to by the operation pointer;

*p equivalent to find a piece of memory through the address, and then manipulate the memory;

*p placed on the left side of the equal sign (assigning values to memory);

*p is placed on the right side of the equal sign (from memory to get the value);

3) The pointer variable and the memory block it points to are two different concepts

Meaning 1: assigning p to p=0x1111; only changes the value of the pointer variable, does not change the point of the content;

Meaning 2: Assigns a value *p= ' a ' to *p, does not change the value of the pointer variable, only changes the value of the memory block pointed to;

Meaning 3: The left side of the equals sign *p for memory assignment; the right side of the equals sign *p the value;

4) A pointer is a data type that refers to the data type of its memory space

Meaning 1: Pointer step size (p++), determined according to the data type of the memory space pointed to

C Language provision: To free memory must be released from the first memory address

A pointer variable and the memory space it points to are two different concepts
1 char *p = NULL; 2 p = (char *)malloc(+); 3  4 if (!p = = NULL) 5 {6      Free (p); 7     p = NULL; 8 }

Free (p) is the content of the memory space that P points to, and the value in the pointer variable p is still present, and P is required to be pointed to null to prevent the wild pointer from being generated

The "C language" pointer is a variable

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.