What is an rvalue in C ?

Posted on:
tags: , , , , , , , ,

What is an rvalue?


Answer:

In FAQ I.9, an lvalue was defined as an expression to which a value can be assigned. It was also explained that an lvalue appears on the left side of an assignment statement. Therefore, an rvalue can be defined as an expression that can be assigned to an lvalue. The rvalue appears on the right side of an assignment statement.

Unlike an lvalue, an rvalue can be a constant or an expression, as shown here:

int x, y;
x = 1; /* 1 is an rvalue; x is an lvalue */
y = (x + 1); /* (x + 1) is an rvalue; y is an lvalue */
As stated in FAQ I.9, an assignment statement must have both an lvalue and an rvalue. Therefore, the following statement would not compile because it is missing an rvalue:
int x;
x = void_function_call() /* the function void_function_call()
returns nothing */

If the function had returned an integer, it would be considered an rvalue because it evaluates into something that the lvalue, x, can store.

Cross Reference:


---------------------------------------------------------------------------------
Posted By Sundeep aka SunTechie

Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on 


No comments:

Post a Comment

< >