What is the Lvalue and Rvalue?

Answer Posted / ashish

An object is a contiguous region of memory storage. An
lvalue (pronounced: L value) is an expression that refers to
such an object. The original definition of lvalue referred
to "an object that can appear on the left-hand side of an
assignment." However, const objects are lvalues, and yet
they cannot appear on the left-hand side of an assignment.
An expression that can appear in the right-hand side of an
expression (but not in the left-hand side of an expression)
is an rvalue. For example:


#include <string>
using namespace std;
int& f();

void func()
{
int n;
char buf[3];
n = 5; // n is an lvalue; 5 is an rvalue
buf[0] = 'a'; //buf[0] is an lvalue, 'a' is an rvalue
string s1 = "a", s2 = "b", s3 = "c"; // "a", "b", "c" are
rvalues
s1 = // lvalue
s2 +s3; //s2 and s3 are lvalues that are implicitly
converted to rvalues
s1 =
string("z"); // temporaries are rvalues
int * p = new int; // p is an lvalue; 'new int' is an
rvalue
f() = 0; // a function call that returns a reference is
an lvalue
s1.size(); // otherwise, a function call is an rvalue
expression
}


An lvalue can appear in a context that requires an rvalue;
in this case, the lvalue is implicitly converted to an
rvalue. An rvalue cannot be converted to an lvalue.
Therefore, it is possible to use every lvalue expression in
the example as an rvalue, but not vice versa.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values.  The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.

2729


How to write a code for reverse of string without using string functions?

1583


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

2543


How can my program discover the complete pathname to the executable from which it was invoked?

665


What does != Mean in c?

594






.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

2007


Differentiate between Macro and ordinary definition.

738


What is ## preprocessor operator in c?

620


Why is c called "mother" language?

867


Why c is called top down?

636


Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.

1772


How do I use strcmp?

647


How do you print only part of a string?

620


What are the usage of pointer in c?

708


Explain the difference between structs and unions in c?

585