【发布时间】:2013-12-28 11:19:14
【问题描述】:
是否可以更改 const global 或 extern 全局变量的值?通过指针?
你可以改变 const 局部变量的值。
【问题讨论】:
-
它是常量,尝试修改它(通过指针或其他方式)将导致未定义的行为。
-
你认为关键字
const是什么意思? -
Mr.Ed Heal,您可以更改 const 局部变量的值。你不知道吗?
-
@selva - 真的。用codepad.org 证明这一点
-
@ED Heal:use in code::blocks 并查看结果 #include
int main(void) { int const index = 10; int *ptr = &index; printf("%d\n",index); *ptr = 20; printf("%d\n",index);返回 1; }