What is the result of & pointer in C?

Which is the result of the following line:

int* ptr; printf("%x, %x\n", ptr, &ptr); 

I know ptr is an address in memory, but what is &ptr ?

+4
source share
7 answers

& ptr will be the address for the memory location where ptr is stored. This is essentially a pointer to a pointer.

+24
source

This is the address of the memory location that contains the address of the original memory location (that is, it is a "pointer to a pointer").

+7
source

&ptr returns the address of the pointer pointer ... pointer to pointer, if you do.

This is often used to allow functions to change where the pointer actually points.

+6
source

ptr is not just a "memory address". ptr is an lvalue, an object in memory that contains an address. Each object in memory has its own address, regardless of what it holds.

Since ptr is an object in memory, it also has its own address. This address is exactly what you get when you do &ptr .

+6
source

a pointer is just a reference to the location of some data in memory. * The pointer gives you the value stored in this memory location. The operator returns the actual memory address, which in this case is a pointer.

+1
source

In C, pointers are just storage containers that hold the address of some other piece of data. In this case, ptr contains the address of some int, and by itself it is only part of the data in memory. So & ptr is the address of a variable that contains the address of some int.

+1
source

& ptr can only be stored in int **var or a double pointer variable, so & ptr is nothing more than a ptr address containing a different address.

0
source

All Articles