We use the const qualifier to declare a variable as a constant. This means that once a variable is initialized, we cannot change its value. There are great benefits to using const. For example, if you have a constant value of PI, you don't want any part of your program to modify that value. Therefore, you should declare it as const.
Objects declared with a const-qualified type may be placed in read-only memory by the compiler, and may not be stored at all if the address of the const object is never obtained in the program. For example,
#include<stdio.h> int main() { const int x = 10; x = 12; return 0; }
[Error] assignment of read-only variable 'x'
The above is the detailed content of Constant qualifier in C. For more information, please follow other related articles on the PHP Chinese website!