小编use*_*970的帖子

如何修改const变量的值?

我能够const在gcc 中更改修改变量的值,但在其他编译器中却没有.我在gcc上尝试了这个代码,它更新了ij(11)的值.使用在线编译器,我得到不同的值.

#include<stdio.h>
void main() {
  const int i=10;
  int *j;
  j = &i;
  (*j)++;
  printf("address of j is %p address of i is %p\n",j,&i);
  printf("i is %d and j is %d\n",i,*j);
}
Run Code Online (Sandbox Code Playgroud)

c gcc const constants

5
推荐指数
3
解决办法
3万
查看次数

标签 统计

c ×1

const ×1

constants ×1

gcc ×1