0
#include <stdio.h>
int main()
{
int i;
i=0;
printf("%d\n%d\n%d\n", i, &i, &(&i));
return 0;
}

i think that &i is just a value of address, and assume that it's 0xFF so &(&i)should be the address of 0xFF but why it's not valid?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52

4 Answers4

7

Unary & operator need an lvalue as its operand and returns an rvalue. &i is an rvalue, therefore &i can't be an operand of &.

haccks
  • 104,019
  • 25
  • 176
  • 264
2

6.5.3.2.

  1. The operand of the unary & operator shall be either a function designator, the result of a [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier.

&i is an address of an object.

This means that unary &cannot be used on &i, as the address doesn't designate an object or a function, nor is the result of [] or * operator.

Your example is effectively: &0, and constant 0 obviously doesn't fall on the above list.

Community
  • 1
  • 1
2501
  • 25,460
  • 4
  • 47
  • 87
1

Don't confuse addresses and pointers.An address is an rvalue.You can't apply the "address of"(&) operator on it.Pointers however are objects.They are lvalue-s and can be the operand of '&'.

machine_1
  • 4,266
  • 2
  • 21
  • 42
0

Easy, look at it this way. You got a bee nest. In a square I put some honey. Using the & operator you refer to that square. Using again the & operator you refer to the square in which the square is located, you can`t do that.

More precisely &i refer to the memory location is i. You can`t refer to the memory location of a memory location.

Myrky
  • 47
  • 1
  • 5