Challenge - 5 Problems
Arithmetic Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed arithmetic operations
What is the output of the following C++ code?
C++
#include <iostream> int main() { int a = 5, b = 3, c = 2; int result = a + b * c - b / c; std::cout << result << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication and division before addition and subtraction.
✗ Incorrect
Multiplication and division (left-to-right) happen before addition and subtraction. So b * c = 3 * 2 = 6, b / c = 3 / 2 = 1 (integer division). Then a + 6 - 1 = 5 + 6 - 1 = 10.
❓ Predict Output
intermediate2:00remaining
Result of integer division and modulo
What is the output of this C++ code snippet?
C++
#include <iostream> int main() { int x = 17, y = 5; std::cout << x / y << " " << x % y << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Integer division discards the decimal part. Modulo gives the remainder.
✗ Incorrect
17 divided by 5 is 3 with remainder 2. So output is '3 2'.
❓ Predict Output
advanced2:00remaining
Output of mixed signed and unsigned arithmetic
What is the output of this C++ code?
C++
#include <iostream> int main() { int a = -3; unsigned int b = 2; std::cout << a + b << std::endl; return 0; }
Attempts:
2 left
💡 Hint
When mixing signed and unsigned, signed is converted to unsigned.
✗ Incorrect
The signed int -3 is converted to unsigned int, which becomes a large number (on 32-bit unsigned, 4294967293). Adding 2 gives 4294967295.
❓ Predict Output
advanced2:00remaining
Result of floating point division and multiplication
What is the output of this C++ program?
C++
#include <iostream> int main() { double x = 7.5, y = 2.5; double result = x / y * y; std::cout << result << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Floating point arithmetic can have small precision errors, but this calculation should return the original value.
✗ Incorrect
7.5 / 2.5 = 3.0, then 3.0 * 2.5 = 7.5 exactly, so output is 7.5.
🧠 Conceptual
expert2:00remaining
Understanding operator precedence and associativity
Given the expression in C++:
Which of the following shows the correct order of operations applied?
int x = 4 + 3 * 2 / 6 - 1;Which of the following shows the correct order of operations applied?
Attempts:
2 left
💡 Hint
Multiplication and division have the same precedence and are evaluated left to right before addition and subtraction.
✗ Incorrect
Multiplication and division are done first, from left to right, then addition and subtraction. So multiply (3*2=6), divide (6/6=1), then add (4+1=5), then subtract (5-1=4).