What is this address coming from?


#1

My question is last two printf function in the code.

[code]#include <stdio.h>

int main(int argc, const char * argv[])
{

int a = 12;
int *a_ptr = &a;
int *test = NULL;

printf("%d\n", *a_ptr); // where pointer varialbe 'a_ptr' is pointing, variable a's value.
printf("%p\n", a_ptr); // address that pointer varialbe 'a_ptr' has.
printf("%p\n", &a_ptr); // address of the pointer variable 'a_ptr'.
printf("%p\n", &a); // address of varialbe a avlue is stored.
printf("%p\n", a); // WHAT IS THIS ADDRESS COMING FROM?
printf("%p\n", test); // IS "0x0 is always NULL's address which is 0?

return 0;

}
[/code]


#2

That statement is kaput because %p requires the address of an object.; it will print the value of a as address of something.
Xcode will warn you: “Conversion specifies ‘void *’ but the argument has type ‘int’”

It should be:

printf ("%p\n", &a);

No, it’s not NULL’s address; 0x0 is NULL’s value in hex notation. (NULL is b[/b].)


#3

Thank you for the reply.
Very satisfied.