Pointer (pointer array, the array pointer, two pointers)

The concept pointer

A pointer is a variable to store the memory address of

Pointer Usage

  1. *Add precedes the tag indicates that the variable is a pointer
  2. Assign a pointer to the int type, and storing the pointer indicates the memory address pointed to an int value
  3. *Together with the variable name represents a pointer value in the pointer points to the memory address, is explained as follows:
//变量a的值为10
int a = 10;
//指针pointer的值为变量a的内存地址
//*pointer可以表示变量a或者10
int *pointer = &a;

Array pointer

A pointer to an array

//()优先级高,所以先声明pointer变量是一个指针
//然后声明这个指针pointer是一个数组指针,数组指针存储的内存地址所指向的值是一个长度为10的int型数组
int (*pointer)[2];
//初始化一个数组
int arr[] = {1, 2};
//初始化这个数组指针
pointer = &arr;
//*pointer就是这个int数组的首地址
//那么**pointer就是这个int数组的第一个值
printf("first value is :%d", **pointer);
printf("first value is :%d", *(*pointer+1));

Pointer array

A pointer storage array

//声明一个数组,只存储了一个int型指针
int *pointer[1];
int a = 1;
int *pa;
pa = &a;
//给数组赋值
pointer[0] = pa;
//pointer[0]是一个int指针,所以要用*来获取指针指向的值
printf("first value is :%d", *pointer[0]);

Two pointers

This special two pointer variables, the memory address is stored in another memory address pointer itself

char a = "a";
//指针p的值就是字符a的内存地址
char *p = &a;
//二级指针pp的值就是指针p的内存地址
char **pp = &p;
Published 118 original articles · won praise 14 · views 50000 +

Guess you like

Origin blog.csdn.net/github_38641765/article/details/90554522