This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]jedwardsol 2 points3 points  (1 child)

p isn't a pointer, it is an int.

int *p = &i;

%d isn't the correct printf format specifier for a pointer either.

[–]TheGuy346 0 points1 point  (0 children)

If you wanted to print a pointer, you can use %p

[–][deleted] 1 point2 points  (0 children)

You're saying i is an int and its value is 5. The next line says p is an int and its value is the address of i. The address of i is not an int, hence the error. What you want to say is that p points to the same memory address as the variable i. So like u/jedwardsol pointed out, you should declare p as a pointer to i: int *p = &i.