#include <unistd.h>
#include <stdio.h>
int main(void)
{
const int a = 9;
const int *ptr;/* 定义指向常量的指针*/
ptr = &a;
*ptr = 1;/* 通过指向常量的指针来改变常量的值 导致 编译错误*/
printf("a= %d\n",a);
return 0;
}
[root@localhost ctest]# gcc constptr.c -o constptr
constptr.c: In function 'main'
constptr.c:8:1: error: assignment of read-only location '*ptr'