TheLogicGuy TheLogicGuy - 1 year ago 72
C Question

Differences between printing a pointer with and without & in C99

Consider the following code:

const char* text = "hi";
printf("%p\n", &text);
printf("%p\n", text);

From where does every
takes the value it prints?

What are the differences?

Answer Source

So let's remember that a pointer is a memory address. text is, as I suspect you know, a pointer to the first (or 0th, depending on how you like to think about it) block of a char array. The & is the "address" operator, which returns the memory address (that is, a pointer to...) whatever comes after it. Since the literal pointer value of text is itself some kind of data, it has to be stored somewhere in memory. So &text returns the address of where the value of text is stored. Like this: POINTERS!!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download