关于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++代码检查更严格。

展开阅读全文

没有更多推荐了,返回首页