Test your understanding of the C basics with these 28 multiple-choice questions — variables, data types, scope, storage classes, and control flow. 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 28 (Easy)
What is the value of sizeof(char) in C?
- 1
- 2
- 4
- Depends on the platform
Show answer
Answer: A — 1
The C standard guarantees sizeof(char) is exactly 1 byte, by definition. All other sizes are measured in multiples of it.
Question 2 of 28 (Easy)
Which of these is NOT a valid C keyword?
- static
- volatile
- function
- goto
Show answer
Answer: C — function
'function' is not a C keyword. static, volatile and goto are all reserved keywords in C.
Question 3 of 28 (Medium)
What is the default storage class for a local (block-scope) variable?
- auto
- register
- static
- extern
Show answer
Answer: A — auto
Local variables have automatic storage duration by default (the 'auto' storage class). They are created on entry to the block and destroyed on exit.
Question 4 of 28 (Easy)
Which is a correct, standard-conforming signature for main?
- int main(void)
- void main()
- main()
- int Main(void)
Show answer
Answer: A — int main(void)
The C standard defines main as 'int main(void)' or 'int main(int argc, char *argv[])'. 'void main()' is non-standard.
Question 5 of 28 (Easy)
What is the result of the integer division 7 / 2 in C?
- 3.5
- 3
- 4
- 3.0
Show answer
Answer: B — 3
Both operands are int, so integer division is performed and the fractional part is discarded, giving 3.
Question 6 of 28 (Easy)
Which keyword makes a variable's value unchangeable after initialization?
- final
- const
- static
- readonly
Show answer
Answer: B — const
'const' qualifies an object as read-only. 'final' and 'readonly' are from other languages; 'static' controls storage/linkage, not mutability.
Question 7 of 28 (Medium)
What does printf return?
- Nothing (void)
- The number of characters written
- 1 on success
- The formatted string
Show answer
Answer: B — The number of characters written
printf returns the number of characters transmitted, or a negative value if an output error occurs.
Question 8 of 28 (Easy)
Which data type is used to store a single character in C?
- string
- char
- byte
- letter
Show answer
Answer: B — char
'char' is the C type for a single character. It is typically 1 byte and can hold a value from the execution character set.
Question 9 of 28 (Medium)
What is the output of this code?
int x = 10;
if (x = 0)
printf("yes");
else
printf("no");
- yes
- no
- Compile error
- Undefined behavior
Show answer
Answer: B — no
x = 0 is an assignment, not a comparison. It sets x to 0 and evaluates to 0 (false). The else branch runs, printing "no".
Full walkthrough with compilable code: read the detailed explanation.
Question 10 of 28 (Easy)
What is the correct way to declare a constant PI in C?
- const float PI = 3.14;
- float constant PI = 3.14;
- define PI = 3.14;
- PI = 3.14;
Show answer
Answer: A — const float PI = 3.14;
'const float PI = 3.14;' is the type-safe way to declare a constant. #define PI 3.14 is also common but has no type.
Question 11 of 28 (Medium)
What does the 'extern' keyword do?
- Marks a variable as external to all translation units
- Declares that a variable is defined in another translation unit
- Prevents a function from being called externally
- Allocates memory externally
Show answer
Answer: B — Declares that a variable is defined in another translation unit
'extern' tells the compiler that the variable or function is defined elsewhere (in another .c file). It provides a declaration without a definition.
Question 12 of 28 (Hard)
What is the output of this code?
int i = 0;
while (i++ < 3)
printf("%d ", i);
- 0 1 2
- 1 2 3
- 0 1 2 3
- 1 2 3 4
Show answer
Answer: B — 1 2 3
i++ evaluates before incrementing: condition i < 3 is checked, then i is incremented. So i is 1, 2, 3 when printed — giving "1 2 3 ".
Full walkthrough with compilable code: read the detailed explanation.
Question 13 of 28 (Medium)
What is the difference between 'break' and 'continue' in a loop?
- break exits the loop; continue skips to the next iteration
- continue exits the loop; break skips to the next iteration
- Both exit the loop
- Both skip to the next iteration
Show answer
Answer: A — break exits the loop; continue skips to the next iteration
'break' terminates the loop entirely. 'continue' skips the rest of the current iteration and goes to the next one.
Question 14 of 28 (Hard)
What is the output of this code?
int i;
for (i = 0; i < 3; i++) {
if (i == 1) continue;
printf("%d ", i);
}
- 0 1 2
- 0 2
- 1
- 0 1
Show answer
Answer: B — 0 2
continue skips the rest of the loop body for i==1, so 1 is not printed. Output is "0 2 ".
Full walkthrough with compilable code: read the detailed explanation.
Question 15 of 28 (Medium)
What is the output of this code?
int x = 5;
switch (x) {
case 5: printf("five");
case 6: printf("six");
default: printf("other");
}
- five
- fivesix
- fivesixother
- other
Show answer
Answer: C — fivesixother
Without break statements, execution falls through all subsequent cases. case 5 matches, then falls into case 6, then default — printing "fivesixother".
Full walkthrough with compilable code: read the detailed explanation.
Question 16 of 28 (Easy)
What does the do-while loop guarantee compared to while?
- It runs faster
- The body executes at least once
- The condition is checked before each iteration
- It cannot be infinite
Show answer
Answer: B — The body executes at least once
In a do-while loop, the body runs first and the condition is checked afterward. This guarantees at least one execution of the body.
Question 17 of 28 (Hard)
What is the output of this code?
int x = 5;
printf("%d %d", x, x++);
- 5 5
- 6 5
- 5 6
- Undefined behavior
Show answer
Answer: D — Undefined behavior
The order of evaluation of function arguments is unspecified in C. Both x and x++ read x with a side effect (x++) — this is undefined behavior.
Full walkthrough with compilable code: read the detailed explanation.
Question 18 of 28 (Medium)
What is an lvalue in C?
- A value on the left side of any expression
- An expression that denotes an object (has a memory location)
- A local variable
- A literal constant
Show answer
Answer: B — An expression that denotes an object (has a memory location)
An lvalue (locator value) refers to an object that occupies identifiable memory. Variables, array elements, and struct members are lvalues. Literals and arithmetic results are rvalues.
Question 19 of 28 (Easy)
Which loop is guaranteed to execute its body at least once?
- for
- while
- do-while
- All of them
Show answer
Answer: C — do-while
do-while checks its condition after each execution, so the body always runs at least once.
Question 20 of 28 (Medium)
What does the 'volatile' keyword tell the compiler?
- The variable is read-only
- The variable may change unexpectedly and must not be optimized away
- The variable is thread-safe
- The variable is stored in a register
Show answer
Answer: B — The variable may change unexpectedly and must not be optimized away
'volatile' tells the compiler the variable can change at any time (e.g., hardware register, signal handler, or another thread). The compiler must read/write it from memory every time and cannot cache it in a register.
Question 21 of 28 (Easy)
What does 'return 0;' in main() conventionally signal?
- Failure
- Success
- The program ran 0 times
- Nothing — it is ignored
Show answer
Answer: B — Success
By convention, main returning 0 (EXIT_SUCCESS) tells the operating system the program completed successfully. Non-zero indicates failure.
Question 22 of 28 (Medium)
What is the output of this code?
int x = 5;
{
int x = 10;
printf("%d ", x);
}
printf("%d", x);
- 5 5
- 10 10
- 10 5
- 5 10
Show answer
Answer: C — 10 5
The inner block declares a new 'x' that shadows the outer one. Inside the block it prints 10; after the block closes, the outer x (5) is back in scope.
Full walkthrough with compilable code: read the detailed explanation.
Question 23 of 28 (Easy)
Which of these is a valid C comment?
- <!– comment –>
- // comment
- ** comment **
- ## comment
Show answer
Answer: B — // comment
// introduces a single-line comment in C99 and later. /* … */ is the traditional block comment. <!– –> is HTML and ## is a preprocessor token-pasting operator.
Question 24 of 28 (Hard)
What is implementation-defined behavior?
- Behavior that is always undefined
- Behavior where the standard deliberately allows compilers to choose, but the choice must be documented
- Behavior specific to the programmer's implementation
- Behavior that differs by CPU architecture
Show answer
Answer: B — Behavior where the standard deliberately allows compilers to choose, but the choice must be documented
Implementation-defined behavior is unspecified by the standard but each implementation must define and document it. Examples: the size of int, signed overflow on right shift. Unlike UB, implementation-defined behavior is predictable for a given compiler.
Question 25 of 28 (Medium)
What is the difference between '==' and '=' in C?
- They are the same operator
- '==' compares values; '=' assigns a value
- '=' compares values; '==' assigns a value
- '==' is only for pointers
Show answer
Answer: B — '==' compares values; '=' assigns a value
'==' is the equality operator — it returns 1 if both sides are equal, 0 otherwise. '=' is the assignment operator — it stores a value into a variable.
Question 26 of 28 (Easy)
What type does C use for boolean values?
- bool
- int
- bit
- boolean
Show answer
Answer: B — int
Before C99, C has no built-in boolean type — any non-zero int is true, 0 is false. C99 introduced _Bool (and <stdbool.h> for bool, true, false macros).
Question 27 of 28 (Medium)
What is the range of a signed 8-bit integer (signed char)?
- 0 to 255
- -128 to 127
- -127 to 127
- -256 to 255
Show answer
Answer: B — -128 to 127
An 8-bit signed integer uses two's complement: -128 to 127 (2^7 = 128 values in each direction, with -128 fitting due to two's complement asymmetry).
Question 28 of 28 (Hard)
What is the output of this code?
int a = 1;
printf("%d", a << 31);
- 2147483648
- -2147483648
- 0
- Undefined behavior
Show answer
Answer: D — Undefined behavior
Shifting a signed 1-bit value into the sign bit is undefined behavior in C (before C23). Left-shifting 1 by 31 moves it into the sign bit of a 32-bit signed int — undefined.
Full walkthrough with compilable code: read the detailed explanation.
How Did You Score?
All 28 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
- C Programs List — 130+ Examples
- C Aptitude Questions and Answers
- Pointers in C — A Complete Guide
- All quiz question walkthroughs
More C Quizzes
- C Operators Quiz — 20 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