[C] C language const and pointer are used together in the order of abbreviation

The order of C language const and pointer used together

const can be used with pointer variables, which can limit the pointer variable itself, and also limit the data pointed to by the pointer. There are several different orders for using const and pointers together:

1. The data pointed to by the pointer, or the pointer itself cannot be modified

const int *p1;//指针所指向的数据是只读的,即p1的值可以修改(指向不同的数据),但它指向的数据不能被修改。
int const *p2;//同上
int * const p3;//指针是只读的,也就是 p3 本身的值不能被修改

2. Neither the data pointed to by the pointer nor the pointer itself can be modified

const int * const p4;
int const * const p5;

Guess you like

Origin blog.csdn.net/phdongou/article/details/114133386