0
0
Cprogramming~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
1:30remaining
Output of compound assignment with addition
What is the output of this C code snippet?
C
int main() {
    int a = 5;
    a += 3;
    printf("%d", a);
    return 0;
}
A8
B3
C0
D5
Attempts:
2 left
πŸ’‘ Hint
The += operator adds the right value to the left variable.
❓ Predict Output
intermediate
1:30remaining
Result of bitwise AND assignment
What will be printed by this C program?
C
int main() {
    int x = 12;  // binary 1100
    x &= 5;      // binary 0101
    printf("%d", x);
    return 0;
}
A12
B5
C4
D1
Attempts:
2 left
πŸ’‘ Hint
Bitwise AND compares each bit of two numbers and returns 1 only if both bits are 1.
❓ Predict Output
advanced
2:00remaining
Output of chained assignment with multiplication
What is the output of this code?
C
int main() {
    int a = 2, b = 3, c = 4;
    a *= b *= c;
    printf("%d %d %d", a, b, c);
    return 0;
}
A6 12 4
B24 12 4
C8 12 4
D24 7 4
Attempts:
2 left
πŸ’‘ Hint
Remember that assignment operators return the assigned value and evaluate right to left.
❓ Predict Output
advanced
1:30remaining
Effect of division assignment on float variable
What will this program print?
C
int main() {
    float f = 10.0f;
    f /= 4;
    printf("%.2f", f);
    return 0;
}
A2.50
B2.00
C2.40
D2.45
Attempts:
2 left
πŸ’‘ Hint
Division assignment divides the variable by the right value and stores the result.
❓ Predict Output
expert
2:00remaining
Final value after multiple compound assignments
What is the final value of variable x after running this code?
C
int main() {
    int x = 1;
    x += 2;
    x *= 3;
    x -= 4;
    x /= 2;
    printf("%d", x);
    return 0;
}
A3
B0
C1
D2
Attempts:
2 left
πŸ’‘ Hint
Apply each assignment operator step by step in order.