C pointer address printing

Yes. All of your statements are correct. However in case of first

int *ip;

it is better to say that ip is a pointer to an int type.

What happens if I print the result of ip?

It will print the address of x.

Will it print the address of variable x, something like

011001110  

No. Addresses are generally represented in hexadecimal. You should use %p specifier to print the address.

printf("Address of x is %p\n", (void *)ip);  

NOTE:
Note that in the above declaration * is not the indirection operator. Instead it specify the type of p, telling the compiler that p is a pointer to int. The * symbol performs indirection only when it appears in a statement.


int x = 1, y = 2;

int *ip; // declares ip as a pointer to an int (holds an address of an int)

ip = &x; // ip now holds the address of x

y = *ip; // y now equals the value held at the address in ip

Tags:

C++

C