Question

I'm doing the following puzzle. Mayby someone could check if I'm choosing the right answer. Have a look.

Which one of the following is a true statement about an lvalue?

1 An lvalue is the result of an arithmetic operation involving quantities of type long int.

2 All lvalues can be used on the right side of an assignment statement.

3 An lvalue is, by definition, the value appearing on the rightmost side of an assignment statement.

4 By definition, an lvalue is the storage space indirectly referenced by a pointer.

5 An lvalue is any quantity capable of appearing on the left side of a shift operator.

Ok, an lvalue is the reference to an object in memory. Therefore, at first sight I thought of the 4th answer but now it seems not the right one, as lvalue is not the stoage itself (and answer 4 implies that). # I'm thinking then that answer 2 is correct as lvalues can be used on left and right hand side of the assignment operator. What do you think?

Was it helpful?

Solution

I'm thinking then that answer 2 is correct as lvalues can be used on left and right hand side of the assignment operator

Yes, this one is true, for this exact reason.

The problem with the other statements:

1) An lvalue is the result of an arithmetic operation involving quantities of type long int.

No. Being long int or not does not have anything to do with lvalues. (long int)42 is of type long int, yet it's not an lvalue.

3) An lvalue is, by definition, the value appearing on the rightmost side of an assignment statement.

No. I don't know if that has any special name, but that's not the definition of lvalue for sure.

4) By definition, an lvalue is the storage space indirectly referenced by a pointer.

No. You don't need any pointers for that. As in int i = 1337;, i is an lvalue. No pointers in the code whatsoever, though.

5) An lvalue is any quantity capable of appearing on the left side of a shift operator.

No. At first glance, lvalues have more to do with the ability to being modified in some way (assignment to a variable or to a member of an array), so this statement would be closer to true if instead of shift operator it read assignment operator. However, not all lvalues can be modified (for example a constant is an lvalue, yet it can't be modified after initializing it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top