C Operators Quiz — 20 Questions with Answers

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);
  1. 11
  2. 12
  3. 13
  4. 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. 1
  2. 3
  3. 0
  4. 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. 1
  2. 2
  3. 3
  4. 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);
  1. 5
  2. 0
  3. 1
  4. 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);
  1. 3
  2. 6
  3. 8
  4. 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?

  1. %d
  2. %u
  3. %f
  4. %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?

  1. \t
  2. \n
  3. \r
  4. \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);
  1. 12
  2. 3
  3. 2
  4. 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);
  1. 6
  2. 7
  3. 15
  4. 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?

  1. The sum of a and b
  2. The larger of a and b
  3. The smaller of a and b
  4. 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);
  1. 0
  2. 1
  3. -1
  4. 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?

  1. 0
  2. -1
  3. 2147483647
  4. 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?

  1. x = 3
  2. x = x + 3
  3. x + 3
  4. 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);
  1. 5
  2. 10
  3. 1
  4. 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?

  1. + (addition)
  2. * (dereference)
  3. () (function call)
  4. = (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. 1
  2. Divide-by-zero crash
  3. 0
  4. 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);
  1. 3
  2. 0
  3. 1
  4. 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);
  1. 3
  2. 1
  3. 0
  4. 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);
  1. 5 6
  2. 6 6
  3. 5 5
  4. 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);
  1. 4
  2. 6
  3. 2
  4. 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

More C Quizzes