I'm starting to learn C. We just did a tutorial on pointers and I was not able to run the sample code on my Linux machine (Mint 17 64 bit), although it works fine on Windows 7 (32 bit). The code is as follows:
#include <stdio.h>
int main() {
int var = 20;
int *ip;
ip = &var;
printf("Address of var variable: %x\n", &var);
printf("Address stored in ip variable: %x\n", ip);
printf("Value of *ip variable: %d\n", *ip);
return 0;
}
The program works as expected in windows with ide code blocks, but on Linux trying to compile in the terminal using GCC, I get the following error:
pointers.c: In function ‘main’:
pointers.c:9:2: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("Address of var variable: %x\n", &var);
^
pointers.c:12:2: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("Address stored in ip variable: %x\n", ip);
^
I would like to know what is happening and how I can get the code to work on Linux.
Thank.
source
share