the usage of const

Pointer

In C programming language, *p represents the value stored in a pointer and p represents the address of the value, is referred as a pointer.

const char* and char const* says that the pointer can point to a constant char and value of char pointed by this pointer cannot be changed. But we can change the value of pointer as it is not constant and it can point to another constant char.

char* const says that the pointer can point to a char and value of char pointed by this pointer can be changed. But we cannot change the value of pointer as it is now constant and it cannot point to another char.

const char* const says that the pointer can point to a constant char and value of int pointed by this pointer cannot be changed. And we cannot change the value of pointer as well it is now constant and it cannot point to another constant char.

Thumb rule is to naming syntax from right to left.

// constant pointer to constant char
const char * const
// constant pointer to char
char * const
// pointer to constant char
const char *
posted @ 2022-05-20 10:59  fire909090  阅读(17)  评论(0编辑  收藏  举报