关于const常量与指针赋值的问题

关于const常量与指针赋值的问题

$gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

源码:

#include <stdio.h>

int main(int argc, const char *argv[])
{
 const int i = 1;
 int *p;
 p = &i;
 *p = 2;
 printf("%d\n", i);
 printf("%d\n", *p);
 return 0;
}

貌似有点问题~~
 
如果换成g++编译则编译不通过,果然C++代码检查更严格。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/bbc3e57ab4e8e9fe681a38c4db393d00.html