Arizona State University (ASU) CSE100 Principles of Programming with C++ Midterm 1 Practice Exam

Session length

1 / 20

True or False: The statement 'int result = 3.0 / 2.0;' assigns 1.5 to the result variable.

True

False

The statement 'int result = 3.0 / 2.0;' evaluates the division of two floating-point numbers, which results in a value of 1.5. However, since 'result' is declared as an integer type, the floating-point result will be converted to an integer.

In C++, when assigning a floating-point number to an integer variable, the fractional part is truncated, meaning that only the whole number part is taken. Therefore, 1.5 becomes 1 when it is assigned to 'result'. As a result, the value stored in 'result' will be 1, not 1.5.

This is why the correct answer is that the statement does not assign 1.5 to the variable; instead, it assigns the truncated integer value 1.

Get further explanation with Examzify DeepDiveBeta

Depends on the compiler

Not enough information

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy