C Language Quiz: Operators
Arithmetic Operators
1. What is the output of:
int a = 5, b = 2;
printf("%d", a + b);
A) 3 B) 5 C) 7 D) 10
2. What is the output of:
int a = 7, b = 3;
printf("%d", a % b);
A) 1 B) 2 C) 3 D) 0
3. What happens if you divide an int by 0?
A) Returns 0 B) Returns 1 C) Runtime error D) Undefined behavior
4. Predict the output:
int a = 10;
a += 5;
printf("%d", a);
A) 5 B) 10 C) 15 D) 20
5. Difference between ++i and i++?
A) No difference B) ++i increments before use, i++ after use C) ++i after use, i++ before use D) Only works in loops
6. Calculate the result:
int a = 10, b = 3;
printf("%f", (float)a / b);
A) 3 B) 3.33 C) 3.0 D) 3.5
Relational Operators
7. Predict the output:
int a = 5, b = 10;
printf("%d", a > b);
A) 0 B) 1 C) 5 D) 10
8. Output of:
int a = 7, b = 7;
printf("%d", a != b);
A) 0 B) 1 C) 7 D) Error
9. Difference between = and ==?
A) Both are same B) = is assignment, == is comparison C) = is comparison, == assignment D) Only used in loops
10. Check if a number is even or odd using operators. Which expression works?
A) num % 2 == 0 B) num / 2 == 0 C) num & 1 == 0 D) Both A and C
11. Predict the output:
int x = 10;
printf("%d", x <= 10);
A) 0 B) 1 C) 10 D) Error
Logical Operators
12. Predict the output:
int a = 5, b = 0;
printf("%d", a && b);
A) 0 B) 1 C) 5 D) Error
13. What does ! operator do?
A) AND B) OR C) Logical NOT D) Increment
14. Output:
int a = 5, b = 10;
printf("%d", (a < b) || (a > 20));
A) 0 B) 1 C) 5 D) 10
15. Difference between && and &?
A) No difference B) && logical AND, & bitwise AND C) && bitwise AND, & logical AND D) Only works in loops
16. Predict output:
int a = 1;
printf("%d", !a);
A) 0 B) 1 C) -1 D) Error
17. Combine arithmetic and logical operators to check if a number is divisible by 2 and greater than 10. Which expression works?
A) (num % 2 == 0) && (num > 10) B) (num % 2 == 1) && (num > 10) C) (num % 2 == 0) || (num > 10) D) (num % 2 == 1) || (num < 10)
18. Predict output:
int a = 4, b = 5;
printf("%d", a * b);
A) 9 B) 20 C) 45 D) 1
19. Which expression checks if a number is between 10 and 50?
A) (num > 10 && num < 50) B) (num >= 10 || num <= 50) C) (num > 10 || num < 50) D) (num < 10 && num > 50)
20. Output of:
int a = 7, b = 2;
printf("%d", a / b);
A) 3.5 B) 3 C) 2 D) 7