W4: Expressions Flashcards
Any C++ expression is one of:
prvalue:
xvalue:
lvalue:
prvalue - a value that does not occupy a location in storage
xvalue - an expiring value that does occupy a location in storage (an object near the end of its lifetime)
lvalue - a locator value that occupies a location in storage
When the compiler creates a temporary object it converts a prvalue into an ______
xvalue
this process is called a temporary materialization conversion.
What is an rvalue?
prvalues and xvalues are called rvalues. An rvalue is a temporary object or subobject, or a value not assocaited with an object.
What is an lvalue?
Both lvalues and xvalues occupy a region of memory and together are called glvalues. A glvalue is a generalized lvalue. It evaluates to an object or a function.
lvalue operands include:
a name that is not an array name
an array element - a[i]
(expression) - where expression is itself an lvalue
a direct member selection - expression.member - where expression is itself an lvalue
an indirect member selection - expression->member - where expression points to an lvalue
a dereferenced address - *expression
a string literal (actually an array of characters)
lvalue operators:
The operands associated with the following three operators must be lvalues:
&
++
–
The left operands associated with the assignment operators must be lvalues:
= \+= -= *= /= %=
Expressions are divided into six operand-related classifications:
primary postfix prefix unary binary ternary
What is a primary expression?
A primary expression consists of a single operand without any operator. The operand may be the name of an entity or a literal.
If the operand is of signed integral type, floating-point type, or pointer type, and the increment/decrement operation produces an overflow/underflow, the result is ________
undefined
If the operand is of unsigned type and its value is 0u, the decrement operator changes the lvalue to __________. If the operand is of unsigned type and its value is the largest storable value, the increment operator changes the lvalue to ___
the largest storable value
0u
he static_cast(v) operator ______ cast away const-ness.
cannot
sizeof() operator evaluates:
sizeof operator evaluates:
The sizeof() operator evaluates the type of its operand and returns its size in bytes.
The sizeof operator (without the parentheses) evaluates the size of a variable, object, or expression.
The result of either sizeof operation is a constant of type size_t (an unsigned integral type).
What will be the output?
std: :cout «_space;sizeof j++ «_space;std::endl;
std: :cout «_space;j «_space;std::endl;
4
1
If the operand of sizeof is an expression, the compiler does not evaluate that expression.
If the sizeof operand is an object of class type, the operation returns…?
the sum of the sizes of the subobjects including any padding.
ex. typedef struct { char a; int b; } A;
int main() { A s;
std::cout << sizeof s << std::endl; }
Outputs: 8
What does the logical negation operator return for each?
bool b = false;
int i = 1;
double* d_ptr = nullptr;
true
false
true