0
0
C++programming~20 mins

Arithmetic operators in C++ - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arithmetic Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A9
B10
C11
D8
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication and division before addition and subtraction.
Predict Output
intermediate
2: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;
}
A3 3
B2 3
C2 2
D3 2
Attempts:
2 left
💡 Hint
Integer division discards the decimal part. Modulo gives the remainder.
Predict Output
advanced
2: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;
}
A4294967295
B-1
C0
D1
Attempts:
2 left
💡 Hint
When mixing signed and unsigned, signed is converted to unsigned.
Predict Output
advanced
2: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;
}
A7.5
B7.499999999999999
C10
D2.5
Attempts:
2 left
💡 Hint
Floating point arithmetic can have small precision errors, but this calculation should return the original value.
🧠 Conceptual
expert
2:00remaining
Understanding operator precedence and associativity
Given the expression in C++:
int x = 4 + 3 * 2 / 6 - 1;
Which of the following shows the correct order of operations applied?
AMultiply, Add, Divide, Subtract
BAdd, Multiply, Divide, Subtract
CMultiply, Divide, Add, Subtract
DDivide, Multiply, Add, Subtract
Attempts:
2 left
💡 Hint
Multiplication and division have the same precedence and are evaluated left to right before addition and subtraction.