I'm trying to understand the concept of pointers. So I wrote a code (from a book I have) but It doesn't complile. Can't understand what is wrong, again I wrote exactly how it is in the book, and I checked if there are some mistakes, but I can't find any...
Here is the code:
#include <stdio.h>
int var = 1;
int *ptr;
int main(void)
{
ptr = &var;
printf("Var = %d", var);
printf("Var = %d", *ptr);
printf("The adress of the variable = %d", &var);
printf("The adress = %d", ptr);
return 0;
}
Here are the errors I got:
ø.c:13:47: error: format specifies type 'int' but the argument has
type 'int *' [-Werror,-Wformat]
printf("The adress of the variable = %d", &var);
~~ ^~~~ ø.c:14:31: error: format specifies type 'int' but the argument has type 'int *'
[-Werror,-Wformat]
printf("The adress = %d", ptr);
~~ ^~~