Test your understanding of C operators with these 20 multiple-choice questions — precedence, arithmetic, bitwise and logical operators, the ternary operator, and the classic undefined-behavior traps. Every question has the answer and a short explanation hidden below it, and the trickier ones link to a full walkthrough with compilable code.
These questions come from our free Android app, C Programming Quiz — 150+ questions across 9 categories with score tracking, if you prefer to practise on your phone.
How to use this page: answer each question yourself before tapping Show answer. If you get one wrong, follow the linked explanation — knowing why the wrong options are wrong is what interviews test.
Question 1 of 20 (Hard)
What is printed by this code?
int x = 5;
printf("%d", x++ + ++x);
- 11
- 12
- 13
- Undefined behavior
Show answer
Answer: D — Undefined behavior
x is modified twice (x++ and ++x) between sequence points with no defined ordering. This is undefined behavior — the standard makes no guarantee about the result.
Full walkthrough with compilable code: read the detailed explanation.
Question 2 of 20 (Easy)
What is the output of this code?
printf("%d", 10 % 3);
- 1
- 3
- 0
- 3.33
Show answer
Answer: A — 1
The modulo operator % gives the remainder. 10 divided by 3 is 3 remainder 1, so the result is 1.
Full walkthrough with compilable code: read the detailed explanation.
Question 3 of 20 (Medium)
What is the output of this code?
int a = 2, b = 3;
printf("%d", a & b);
- 1
- 2
- 3
- 0
Show answer
Answer: B — 2
Bitwise AND: 2 is 10 and 3 is 11 in binary. 10 & 11 = 10, which is 2.
Full walkthrough with compilable code: read the detailed explanation.
Question 4 of 20 (Medium)
What is the output of this code?
printf("%d", 5 || 0);
- 5
- 0
- 1
- Compile error
Show answer
Answer: C — 1
Logical OR yields an int: 1 for true, 0 for false. Since 5 is non-zero (true), the expression evaluates to 1.
Full walkthrough with compilable code: read the detailed explanation.
Question 5 of 20 (Medium)
What is the output of this code?
printf("%d", 1 << 3);
- 3
- 6
- 8
- 16
Show answer
Answer: C — 8
Left shift by 3 multiplies by 2^3 = 8. So 1 << 3 is 8.
Full walkthrough with compilable code: read the detailed explanation.
Question 6 of 20 (Easy)
Which format specifier prints an unsigned integer?
- %d
- %u
- %f
- %c
Show answer
Answer: B — %u
%u prints an unsigned int. %d is signed int, %f is floating point, and %c is a character.
Question 7 of 20 (Easy)
Which escape sequence represents a newline?
- \t
- \n
- \r
- \0
Show answer
Answer: B — \n
\n is the newline character. \t is a tab, \r is carriage return, and \0 is the null character.
Question 8 of 20 (Medium)
What is the output of this code?
int a = 6;
printf("%d", a >> 1);
- 12
- 3
- 2
- 6
Show answer
Answer: B — 3
Right shift by 1 divides by 2^1. 6 >> 1 = 3.
Full walkthrough with compilable code: read the detailed explanation.
Question 9 of 20 (Medium)
What is the output of this code?
int a = 5;
printf("%d", a ^ 3);
- 6
- 7
- 15
- 2
Show answer
Answer: A — 6
Bitwise XOR: 5 is 101 and 3 is 011. 101 ^ 011 = 110 = 6.
Full walkthrough with compilable code: read the detailed explanation.
Question 10 of 20 (Easy)
What does the ternary operator '(a > b) ? a : b' compute?
- The sum of a and b
- The larger of a and b
- The smaller of a and b
- 1 if a > b, 0 otherwise
Show answer
Answer: B — The larger of a and b
The ternary chooses a when the condition is true, b otherwise — selecting the maximum.
Question 11 of 20 (Medium)
What is the output of this code?
int x = 0;
printf("%d", !x);
- 0
- 1
- -1
- Compile error
Show answer
Answer: B — 1
Logical NOT: !0 is 1 (true), !non-zero is 0 (false).
Full walkthrough with compilable code: read the detailed explanation.
Question 12 of 20 (Hard)
What is the value of ~0 on a 32-bit int?
- 0
- -1
- 2147483647
- 4294967295
Show answer
Answer: B — -1
Bitwise NOT flips all bits. ~0 makes all 32 bits 1, which in two's complement represents -1.
Question 13 of 20 (Easy)
What does the compound assignment 'x += 3;' mean?
- x = 3
- x = x + 3
- x + 3
- x = x * 3
Show answer
Answer: B — x = x + 3
'x += 3' is shorthand for 'x = x + 3' — it adds 3 to x and stores the result back in x.
Question 14 of 20 (Hard)
What is the output of this code?
int a = 5, b = 10;
printf("%d", a < b ? a : b);
- 5
- 10
- 1
- 0
Show answer
Answer: A — 5
a < b is true (5 < 10), so the ternary evaluates to a, which is 5.
Full walkthrough with compilable code: read the detailed explanation.
Question 15 of 20 (Medium)
Which operator has the highest precedence in C?
- + (addition)
- * (dereference)
- () (function call)
- = (assignment)
Show answer
Answer: C — () (function call)
Function call (), array subscript [], and member access . and -> all share the highest precedence in C.
Question 16 of 20 (Medium)
What is the output of this code?
int a = 0;
printf("%d", a || (1 / a));
- 1
- Divide-by-zero crash
- 0
- Undefined behavior
Show answer
Answer: D — Undefined behavior
a is 0 (false), so || does NOT short-circuit — it only skips the right side when the left is true (non-zero). Here the right side 1/a is evaluated, causing integer division by zero, which is undefined behavior in C.
Full walkthrough with compilable code: read the detailed explanation.
Question 17 of 20 (Easy)
What is the output of this code?
printf("%d", 3 == 3);
- 3
- 0
- 1
- true
Show answer
Answer: C — 1
Relational operators return int: 1 for true, 0 for false. 3 == 3 is true so the result is 1.
Full walkthrough with compilable code: read the detailed explanation.
Question 18 of 20 (Medium)
What is the output of this code?
int a = 10, b = 3;
printf("%d", a % b);
- 3
- 1
- 0
- 3.33
Show answer
Answer: B — 1
10 % 3: 10 / 3 = 3 remainder 1. The modulo operator gives the remainder, which is 1.
Full walkthrough with compilable code: read the detailed explanation.
Question 19 of 20 (Hard)
What is the output of this code?
int a = 5;
printf("%d %d", a, ++a);
- 5 6
- 6 6
- 5 5
- Undefined behavior
Show answer
Answer: D — Undefined behavior
The order of evaluation of function arguments is unspecified. ++a is a side effect with unsequenced evaluation relative to reading a. This is undefined behavior.
Full walkthrough with compilable code: read the detailed explanation.
Question 20 of 20 (Medium)
What is the output of this code?
int a = 4, b = 2;
printf("%d", a | b);
- 4
- 6
- 2
- 0
Show answer
Answer: B — 6
Bitwise OR: 4 is 100, 2 is 010. 100 | 010 = 110 = 6.
Full walkthrough with compilable code: read the detailed explanation.
How Did You Score?
All 20 correct means this topic is interview-ready — try the harder timed rounds in the C Programming Quiz app. Missed a few? The guides below cover everything these questions test.
Keep Practising
- Arithmetic Operators in C — Complete Guide
- Sequence Points in C and Undefined Behavior
- C Aptitude Questions and Answers
- All quiz question walkthroughs
More C Quizzes
- C Basics Quiz — 28 Questions with Answers
- C Memory Management Quiz — 19 Questions with Answers
- C Pointers Quiz — 18 Questions with Answers
- C Arrays and Strings Quiz — 18 Questions with Answers
- C Functions Quiz — 15 Questions with Answers
- C Structs and Unions Quiz — 13 Questions with Answers
- C File I/O Quiz — 13 Questions with Answers
- C Preprocessor Quiz — 11 Questions with Answers