C LANGUAGE QUESTION All pointer variables store addresses If

C LANGUAGE QUESTION

All pointer variables store addresses. If you read a pointer variable, such as the printf() statement below, you get the address it stores.

printf(“The value of pI is 0x%p.\ , pI);

If you use the address-of & operator on a pointer variable, you get a different address. Why?

Solution

Example:

int a = 10;

Now to get the address of the variable a you either can store it in a pointer variable or use & of operator.

Using pointer variable

int *p1 = &a;

now pointer stores the address of the variable a.

If you use p1 as it is it will print the address of a

if you dereference it *p1 then it will show the content of a

If you use & of operator on p1 then p1 is also a variable &p1 will give the address of pointer variable p1 not the address of variable a.

C LANGUAGE QUESTION All pointer variables store addresses. If you read a pointer variable, such as the printf() statement below, you get the address it stores.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site