指向const的指针

时间:2016-06-17 10:07:52

标签: c++ c

常量应该在只读内存中,那么指向const的指针如何能够改变其值。

#include<stdio.h>
int main(void){
const int c=10;
int* p=&c;

*p=1;

printf("c:%d",c);//value of const changed.
return 0;
}

输出: C:1

编译器:gcc 4.8.5

0 个答案:

没有答案