R-Value of Expression : C Programming



In the previous chapter we have learnt about the Lvalue of an expression in this chapter we are going to learn R-Value of Expression.

What is R-Value of Expression ?

  1. R Value stands for Right value of the expression.
  2. In any Assignment statement R-Value of Expression must be anything which is capable of returning Constant Expression or Constant Value.
  3. R Value Can be anything of following -
Examples of R-Value of Expression
Variable Constant
Function Macro
Enum Constant Any other data type

Diagram Showing Lvalue :

Example of R-Value of Expression

#include<stdio.h>
int main()
{
int num;
num = 5;
return(0);
}

In the above example, Constant Value 5 is assigned to the variable will be considered as right Value of the variable.

Tips : R-Value of Expression

Tip 1 : R value may be constant or constant expression

num = 20;      //Constant RValue
num = 20 + 20; //Constant Expression as RValue
  1. In the example, we have assigned constant value to the variable.
  2. Constant value “20” is considered as RValue.
  3. In the next line we have assigned constant expression to the variable. “20 + 20” will be evaluated first and then result of expression will be assigned to an Variable.

Tip 2 : R value may be MACRO

#define MAX 20
main() {
   int num = MAX;
}

If we have defined a MACRO then we can use MACRO as right value. In the above example we have assigned the 20 to the variable “num”.

In case if we defined the MACRO value of different data type then it may results into compile error.

Tip 3 : R Value may be variable

#define MAX 20
main() 
{
   int flag = 0;
   int num  = flag;
}

For more information , Visit MSDN library.