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 reviewWhich 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 GameQuestions by ladder level
Which C17 standard header supplies the names bool and true in the declaration bool active = true?
- <stdbool.h>
- <stddef.h>
- <stdint.h>
- <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.
Which declaration creates an int named limit that can be read but cannot be assigned a new value through its name?
- static int limit = 12;
- int limit = 12;
- const int limit = 12;
- 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.
What type does the ordinary C17 character constant 'Q' have?
- char
- int
- unsigned char
- 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.
What value does the C expression (3 < 5) + (6 == 6) produce?
- 11
- 1
- 0
- 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.
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?
- 8
- 4
- 0
- -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.
After the statements int n = 4; int written = n++; what are the values of written and n, in that order?
- 4 and 5
- 5 and 5
- 5 and 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.
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 and 1
- 0 and 1
- 1 and 0
- 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.
What is total after int total = 0; for (int n = 12; n > 0; n /= 2) { total += n; }?
- 24
- 21
- 22
- 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.
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?
- 6
- 2
- 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.
In C17, what are all five elements of the array declared by int counts[5] = {7, 3}?
- [0, 0, 0, 7, 3]
- [7, 3, 7, 3, 7]
- [7, 3, 1, 1, 1]
- [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.
In the same block as int values[6] = {2, 4, 6, 8, 10, 12}, what is the value of sizeof values / sizeof values[0]?
- 12
- 3
- 6
- 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.
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?
- 7 and 7
- 4 and 7
- 4 and 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.
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?
- 4 and 0
- 3 and 4
- 0 and 3
- 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.
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?
- 6 and 3
- 3 and 3
- 6 and 6
- 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.
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?
- (5, 8)
- (3, 4)
- (5, 9)
- (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).