C Programming Multiple-Choice Quiz

Practice portable C17 with short questions about types, comparisons, loops, fixed-size arrays, functions, and structs. Each answer includes a short explanation.

Ages 13+ · introductory C learners and classroom review

Question 1 of 15

$100

Which C17 standard header supplies the names bool and true in the declaration bool active = true?

Ready to play?

Open at Step 3 with every question loaded. Play solo, host live, or customize your game.

Play & Customize Game

Questions by ladder level

Level 1 · Boolean values

Which C17 standard header supplies the names bool and true in the declaration bool active = true?

  1. <stdbool.h>
  2. <stddef.h>
  3. <stdint.h>
  4. <limits.h>
Show answer and explanation

Correct answer: A. <stdbool.h>

In C17, stdbool.h defines bool as an alias for the built-in _Bool type. It also supplies the true and false macros.

Question reference

Level 2 · Declaring a read-only integer

Which declaration creates an int named limit that can be read but cannot be assigned a new value through its name?

  1. static int limit = 12;
  2. int limit = 12;
  3. const int limit = 12;
  4. unsigned int limit = 12;
Show answer and explanation

Correct answer: C. const int limit = 12;

The const qualifier makes limit nonmodifiable through its name. Its initializer supplies the value 12.

Question reference

Level 3 · Character constants

What type does the ordinary C17 character constant 'Q' have?

  1. char
  2. int
  3. unsigned char
  4. double
Show answer and explanation

Correct answer: B. int

An ordinary single-quoted character constant has type int. Its value comes from the chosen character in the execution character set.

Question reference

Level 4 · Results of comparisons

What value does the C expression (3 < 5) + (6 == 6) produce?

  1. 11
  2. 1
  3. 0
  4. 2
Show answer and explanation

Correct answer: D. 2

Both comparisons are true and each yields the int value 1. Adding those two results gives 2.

Question reference

Level 5 · A condition with a nonzero value

A C snippet starts with int choice = 0. It then runs if (-2) choice = 4; else choice = 8; What is the resulting value of choice?

  1. 8
  2. 4
  3. 0
  4. -2
Show answer and explanation

Correct answer: B. 4

C executes the first branch of this if statement when the condition compares unequal to zero. The value -2 therefore selects the assignment of 4.

Question reference

Level 6 · Postfix increment

After the statements int n = 4; int written = n++; what are the values of written and n, in that order?

  1. 4 and 5
  2. 5 and 5
  3. 5 and 4
  4. 4 and 4
Show answer and explanation

Correct answer: A. 4 and 5

The postfix expression n++ yields the old value 4 for written. By the end of that statement, n has increased to 5.

Question reference

Level 7 · Short-circuit evaluation

The int variables count and allowed both start at 0. The program evaluates int result = allowed && ++count. What are the resulting values of result and count?

  1. 1 and 1
  2. 0 and 1
  3. 1 and 0
  4. 0 and 0
Show answer and explanation

Correct answer: D. 0 and 0

The left operand is zero, so && yields 0 and skips its right operand. The variable count stays at 0 because its increment never runs.

Question reference

Level 8 · Tracing a for loop

What is total after int total = 0; for (int n = 12; n > 0; n /= 2) { total += n; }?

  1. 24
  2. 21
  3. 22
  4. 18
Show answer and explanation

Correct answer: C. 22

The loop adds 12, 6, 3, and 1. The next integer division changes n to 0, ending the loop with a total of 22.

Question reference

Level 9 · Following switch cases

The int score starts at 0. The program runs switch (2) { case 1: score += 1; break; case 2: score += 2; case 3: score += 4; break; default: score = 8; }. What is score afterward?

  1. 6
  2. 2
  3. 4
  4. 8
Show answer and explanation

Correct answer: A. 6

Execution enters at case 2 and adds 2. It continues into case 3 and adds 4 before break exits the switch.

Question reference

Level 10 · Fixed-size array initialization

In C17, what are all five elements of the array declared by int counts[5] = {7, 3}?

  1. [0, 0, 0, 7, 3]
  2. [7, 3, 7, 3, 7]
  3. [7, 3, 1, 1, 1]
  4. [7, 3, 0, 0, 0]
Show answer and explanation

Correct answer: D. [7, 3, 0, 0, 0]

The two explicit values initialize the first two elements. C initializes the remaining int elements to zero.

Question reference

Level 11 · Counting array elements

In the same block as int values[6] = {2, 4, 6, 8, 10, 12}, what is the value of sizeof values / sizeof values[0]?

  1. 12
  2. 3
  3. 6
  4. 24
Show answer and explanation

Correct answer: C. 6

The numerator measures the whole array in bytes. The denominator measures one element, so their quotient gives the six-element count.

Question reference

Level 12 · Passing an integer value

The function int addThree(int value) { value += 3; return value; } is called as int result = addThree(a), where a is an int set to 4. What are a and result afterward?

  1. 7 and 7
  2. 4 and 7
  3. 4 and 4
  4. 7 and 4
Show answer and explanation

Correct answer: B. 4 and 7

The function receives the value of a in a local parameter. It updates that parameter and returns 7. The caller's a stays at 4.

Question reference

Level 13 · Initializing named struct members

Given struct Grid { int rows; int columns; }, the program declares struct Grid grid = {.columns = 3, .rows = 4}. What are grid.rows and grid.columns, in that order?

  1. 4 and 0
  2. 3 and 4
  3. 0 and 3
  4. 4 and 3
Show answer and explanation

Correct answer: D. 4 and 3

The member names in the initializer determine where each value goes. Rows receives 4 and columns receives 3.

Question reference

Level 14 · Copying a struct

A struct Point has int members row and col. The program creates struct Point first = {2, 6} and struct Point next = first, then sets next.col = 3. What are first.col and next.col afterward?

  1. 6 and 3
  2. 3 and 3
  3. 6 and 6
  4. 3 and 6
Show answer and explanation

Correct answer: A. 6 and 3

Initializing next from first copies the struct value into a separate object. The later assignment changes only the col member of next.

Question reference

Level 15 · Returning a struct through a loop

A struct Pair holds ints left and right. The function advance(struct Pair p, int step) adds step to p.left, adds the updated p.left to p.right, and returns p. A struct Pair value starts at (2, 1). A loop replaces it with advance's result first for step 1, then for step 2. What final pair does it hold?

  1. (5, 8)
  2. (3, 4)
  3. (5, 9)
  4. (2, 1)
Show answer and explanation

Correct answer: C. (5, 9)

The first call returns (3, 4). The second uses that pair, raises left to 5, and adds 5 to right to get (5, 9).

Question reference