Xiao Bai's basic summary of C language pointers, and Xiao Bai's C language pointers

Source: Internet
Author: User

Xiao Bai's basic summary of C language pointers, and Xiao Bai's C language pointers

Pointer

A pointer is the address pointing to a piece of memory space, a pointer variable is a variable, and a variable storing the first address of a piece of memory space. We generally refer to pointers as pointer variables.

Pointer definition and assignment:

Type Description * variable name column such as int * p;

Difference int * p = NULL and * p = NULL

  

Int * p = NULL; // defines the pointer Variable p, and sets the value of p to 0x00000000 at the same time, instead of setting the value of * p to 0x0000000, this process is called initialization int * p; * p = NULL; // defines the pointer Variable p, Set * p to NILL, that is, assign NULL to the memory pointed to by p, however, the memory referred to by p may be invalid, and the compilation may display a memory access error. Then, make the following changes to give it a valid memory. Int I = 10; int * p = & I; * p = NULL; // The value in I is changed from 10 to 0, and the p value is not changed, that is, the memory address is not changed.

 

 

Pointer size

Int * P; sizeof (p); // the pointer size is determined by the number of digits of the computer. The 32-bit Host size is 4 bytes, And the 64-bit Host size is 8 bytes.

 

Pointer operation

It should be noted that the pointer type, plus 1 is the size of a pointer type.

  

Int a [10]; int * p = & a; // + 1, with the sizeof (int) * 1 byte added instead of sizeof (int [10]) * 1 byte

 

Usage type of pointer

Pointer format

Array form

  

Int a [10]; int * P = a; p [0] = 1; // pointer array form * (p + 1) = 2; // pointer form

 

 

The compilation process of modifying content through pointers

1. Find the address of the pointer variable

2. Find the content address through the address of the pointer variable

3. Find the content through the address

4. modify content

 

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.