W4: Expressions Flashcards

1
Q

Any C++ expression is one of:

prvalue:
xvalue:
lvalue:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When the compiler creates a temporary object it converts a prvalue into an ______

A

xvalue

this process is called a temporary materialization conversion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an rvalue?

A

prvalues and xvalues are called rvalues. An rvalue is a temporary object or subobject, or a value not assocaited with an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an lvalue?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

lvalue operands include:

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

lvalue operators:

A

The operands associated with the following three operators must be lvalues:

&
++

The left operands associated with the assignment operators must be lvalues:

=
\+=
-=
*=
/=
%=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Expressions are divided into six operand-related classifications:

A
primary
postfix
prefix
unary
binary
ternary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a primary expression?

A

A primary expression consists of a single operand without any operator. The operand may be the name of an entity or a literal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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 ________

A

undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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 ___

A

the largest storable value

0u

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

he static_cast(v) operator ______ cast away const-ness.

A

cannot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

sizeof() operator evaluates:

sizeof operator evaluates:

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What will be the output?

std: :cout &laquo_space;sizeof j++ &laquo_space;std::endl;
std: :cout &laquo_space;j &laquo_space;std::endl;

A

4
1

If the operand of sizeof is an expression, the compiler does not evaluate that expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If the sizeof operand is an object of class type, the operation returns…?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the logical negation operator return for each?

bool b = false;
int i = 1;
double* d_ptr = nullptr;

A

true
false
true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which expressions differ from other binary expressions (evaluate left to right instead of right to left)

A

Logical expressions
&& // and
|| // or

17
Q

If the operands in the expression are not of the type defined for the operator, one of the operands must be converted to a compatible type.

A
long double	highest
double	...
float	...
unsigned long long	...
long long	...
unsigned long	...
long	...
unsigned int	...
int	...
unsigned char	...
char	...
bool	lowest