0
0
C++programming~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Assignment Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of compound assignment with multiplication
What is the output of this C++ code snippet?
C++
#include <iostream>
int main() {
    int a = 5;
    a *= 3 + 2;
    std::cout << a << std::endl;
    return 0;
}
ASyntax error
B25
C15
D10
Attempts:
2 left
💡 Hint
Remember operator precedence: multiplication assignment and addition.
Predict Output
intermediate
2:00remaining
Result of chained assignment
What is the value of variable c after running this code?
C++
#include <iostream>
int main() {
    int a, b, c;
    a = b = c = 7;
    c += 3;
    std::cout << c << std::endl;
    return 0;
}
A7
B3
C10
D0
Attempts:
2 left
💡 Hint
Look at the chained assignment and then the addition assignment.
Predict Output
advanced
2:00remaining
Effect of bitwise assignment operator
What is the output of this C++ program?
C++
#include <iostream>
int main() {
    unsigned int x = 12; // binary 1100
    x >>= 2;
    std::cout << x << std::endl;
    return 0;
}
A3
B48
C6
DSyntax error
Attempts:
2 left
💡 Hint
Right shift operator divides by powers of two.
Predict Output
advanced
2:00remaining
Output of combined assignment with logical operators
What is the output of this code snippet?
C++
#include <iostream>
int main() {
    int a = 5;
    a &= 3;
    std::cout << a << std::endl;
    return 0;
}
A0
B7
C1
D2
Attempts:
2 left
💡 Hint
Use bitwise AND on the binary forms of 5 and 3.
🧠 Conceptual
expert
2:00remaining
Understanding behavior of assignment in expressions
Consider this code snippet. What is the value of y after execution?
C++
#include <iostream>
int main() {
    int x = 4;
    int y = (x += 3) * 2;
    std::cout << y << std::endl;
    return 0;
}
A14
B10
C8
D7
Attempts:
2 left
💡 Hint
Remember that assignment expressions return the assigned value.