Assignment operator in C | L- value Error in C programming

Spread the love
Assignment operator in C
 

Assignment Operator( = ) :

  • Assignment operator is used assigning values.in general assignment operator assigns the value of the right hand side operand to Left hand side Operand.
  • Assignment operator is binary operator so it must need two operands.
  • Assignment operator symbol is = (equal to).
  • Assignment operator have two values those are Left-side value also called as L-Value and Right-side Value also called as R-Value.
  • It copies R-value into L-value.
  • Left-side value of Assignment Operator must be Variable.
  • Assignment operator have lowest precedence than all operators except Comma Operator. see full priority table/precedence table 

Syntax of Assignment operator :

 
L-value = R-value ;

Example :

 
  1. #include<stdio.h>
  2. int main()
  3. {
  4.         int x;
  5.         x = 10;         // assignment operator.
  6.         printf(“value of x is : %d n,x);
  7.         return 0;
  8. }
In above Example x = 10 is assignment operation.
Here x is left-side value and 10 is right side value, so 10 is assigned to x. So next printf will give 10 as X value.
Output :
 Value of X is : 10

Example 2 : L – Value Error in C programming 

  1. #include<stdio.h>
  2. int main()
  3. {
  4.         int x=10;
  5.         20 = x ;
  6.         printf(“value of x is : %d n,x);
  7.         return 0;
  8. }
Left-side Value must be Variable otherwise it can not store data. so we will get l-value Error
Output :

Also Read :

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer, Presently working as a Software Engineer. I love Linux and Open Source. Apart from that, I love to explore new technologies and things.

You may also like...

2 Responses

Leave a Reply