我们只是在指针上做了一个关于C的教训,我在linux机器上运行示例代码时遇到了麻烦(Mint 17 64 bit)虽然它在Windows 7(32位)上正常运行.代码如下:
#include <stdio.h>
int main() {
int var = 20; //actual variable declaration
int *ip; //pointer declaration
ip = &var; //store address of var in pointer
printf("Address of var variable: %x\n", &var);
//address stored in pointer variable
printf("Address stored in ip variable: %x\n", ip);
//access the value using the pointer
printf("Value of *ip variable: %d\n", *ip);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该程序在具有代码块ide的Windows上按预期运行,但在linux上尝试使用GCC在终端中编译时出现以下错误:
pointers.c: In function ‘main’:
pointers.c:9:2: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument …Run Code Online (Sandbox Code Playgroud)