Not able to understand error condition wrt lvalues

前端 未结 3 635
小蘑菇
小蘑菇 2021-01-22 02:05

I am a beginner in programming and was trying out some combinations.

#include


int main()
{
int a=5;

printf(\"%d\",&a); // STATEMENT 1
print         


        
3条回答
  •  被撕碎了的回忆
    2021-01-22 02:26

    a++ and ++a and & all three of them needs lvalue to operate on and when operated they return the rvalue

    So when you do &(a++)

    First, (a++) is performed  -> a is taken as lvalue and (a++) returns rvalue
    
    Second, &(a++) is performed -> a++ returns rvalue but & needs lvalue so lvalue is
    missing,therefore an error.
    

    For this similar reason you can't perform any of these:

    ++(a++) : lvalue missing
    (++a)++ : lvalue missing
    a++++   : lvalue missing
    ++++a   : lvalue missing
    

提交回复
热议问题