MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Fundamental Programming
Operators & Expressions
Beginner
Q
In C++, what is the result of int a = 5; int b = a++ + ++a;?
A13
B12
C11
DUndefined behavior
Correct Answer:
D. Undefined behavior
Explanation:
The two operands of + are unsequenced relative to each other, and both modify a. That makes the expression undefined behavior, even under C++17.
ALSO KNOW (related points):
• In C++, what happens with int i = 0; if (i != 0 && 10 / i > 1) {...}? → The condition is false and no division occurs
• In C++, what is -7 / 2? → -3
• In C++, what is -7 % 3? → -1
• In C++, what are the values of 6 & 3 and 6 && 3? → 2 and 1 (true)
• In C++, what does this print?: int i = 5;; size_t s = sizeof(i++);; cout