Search code examples
coperator-precedence

Why a++=5 is error?


I just wrote a code in c

#include <stdio.h>

int main()
{
    int a=0;
    option1: a++=5;
    option2: ++a=5;
    printf("%d\n",a);

    return 0;
}

but it doesnt compiled with error

lvalue required as left operand of assignment

why its an error? thanks!


Solution

  • Because, like your compiler says, a++ is not an lvalue, it's a rvalue. You will find more information about lvalue and rvalue here.