The difference between the simple variable i and * (& i);

I have the following C program:

int main()
{
    int i = 5;
    printf("Simple value of i = %d", i);
    printf("\nPointer value of i = %d", *(&i));
    return 0;
}

Both of them printf()will print the same as 5. According to my understanding, it is &used for the value of the address, and is *used to select the value at this address.

My question is: why do we need *(&i)if the same thing can be achieved by a simple variable i?

+6
source share
2 answers

My question is why do we need * (& i) if the same thing can be achieved with the simple variable i?

Well, you do not need it.

The expression is *(&i)equivalent i.

6.5.3.2 :

* . , ; , lvalue, . '' '', '' type ''. , * undefined.102)

:

, & * E E ( E - ) & (E1 [E2]) - ((E1) + (E2)). [..]

C , (. 5.1.2.3 ) . , :

printf("\nPointer value of i = %d", *(&i));

, , :

printf("\nPointer value of i = %d", i);

C.

+7

*(&i) , i.

, , , i ( CPU , ).

+6

All Articles