歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 關於const常量與指針賦值的問題

關於const常量與指針賦值的問題

日期:2017/3/1 9:58:24   编辑:Linux編程

關於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++代碼檢查更嚴格。

Copyright © Linux教程網 All Rights Reserved