pointer

 

storage unit:

The bytes occupied by different types of data are different, and a rectangular grid above represents 4 bytes

variable:

The value of the variable is what is stored. The name of the variable is equivalent to the name of the address. Allocate the space according to the variable type; refer to the value of the variable through the variable name, the program will convert the variable name to the address of the variable after compilation, the variable name is equivalent to the address name, such as i is equivalent to 2000 , the access to the variable value is performed through the address of. Variable access is direct access.

pointer:

Pointer = address, both names describe a content, and the address of a variable is called the variable's pointer.

pointer variable:

Holds the address (pointer) of another variable.

int *i_pointer ; // Define pointer variable

i_pointer=&i; // Refer to the pointer variable and store the address of i in the pointer variable i_pointer . The i_pointer pointer variable is also an address variable

 

Example of use:

#include " stdio.h " // Preprocessing directives

void main()
{
    int a = 1 , b = 2 ;
     void swap( int *p, int * q);
     int *a_p, *b_p; // define pointer variable type name *pointer variable name 
    a_p = &a; // reference pointer variable, $ Add variable a, take the address of a 
    b_p = &b; // reference pointer variable 
    printf( " %d,%d\n " , &a, & b);
    printf( " %d,%d\n " , a_p, b_p); // pointer variable, storage address 
    printf( " %d,%d\n " , *a_p, *b_p); // pointer variable a_p plus * You can get the object pointed to by the pointer stored in the pointer variable 
    swap(a_p,b_p); // Indicate that p and q are pointer variables 
    printf( " %d,%d\n " , &a, & b);
    printf("%d,%d\n", a_p, b_p);
    printf("%d,%d\n", *a_p, *b_p);
}

 

array of pointer references

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325171451&siteId=291194637