C Basics Quiz — 28 Questions with Answers

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

  1. static
  2. volatile
  3. function
  4. 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?

  1. auto
  2. register
  3. static
  4. 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?

  1. int main(void)
  2. void main()
  3. main()
  4. 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?

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

  1. final
  2. const
  3. static
  4. 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?

  1. Nothing (void)
  2. The number of characters written
  3. 1 on success
  4. 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?

  1. string
  2. char
  3. byte
  4. 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");
  1. yes
  2. no
  3. Compile error
  4. 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?

  1. const float PI = 3.14;
  2. float constant PI = 3.14;
  3. define PI = 3.14;
  4. 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?

  1. Marks a variable as external to all translation units
  2. Declares that a variable is defined in another translation unit
  3. Prevents a function from being called externally
  4. 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);
  1. 0 1 2
  2. 1 2 3
  3. 0 1 2 3
  4. 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?

  1. break exits the loop; continue skips to the next iteration
  2. continue exits the loop; break skips to the next iteration
  3. Both exit the loop
  4. 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);
}
  1. 0 1 2
  2. 0 2
  3. 1
  4. 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");
}
  1. five
  2. fivesix
  3. fivesixother
  4. 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?

  1. It runs faster
  2. The body executes at least once
  3. The condition is checked before each iteration
  4. 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++);
  1. 5 5
  2. 6 5
  3. 5 6
  4. 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?

  1. A value on the left side of any expression
  2. An expression that denotes an object (has a memory location)
  3. A local variable
  4. 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?

  1. for
  2. while
  3. do-while
  4. 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?

  1. The variable is read-only
  2. The variable may change unexpectedly and must not be optimized away
  3. The variable is thread-safe
  4. 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?

  1. Failure
  2. Success
  3. The program ran 0 times
  4. 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);
  1. 5 5
  2. 10 10
  3. 10 5
  4. 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?

  1. <!– comment –>
  2. // comment
  3. ** comment **
  4. ## 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?

  1. Behavior that is always undefined
  2. Behavior where the standard deliberately allows compilers to choose, but the choice must be documented
  3. Behavior specific to the programmer's implementation
  4. 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?

  1. They are the same operator
  2. '==' compares values; '=' assigns a value
  3. '=' compares values; '==' assigns a value
  4. '==' 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?

  1. bool
  2. int
  3. bit
  4. 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)?

  1. 0 to 255
  2. -128 to 127
  3. -127 to 127
  4. -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);
  1. 2147483648
  2. -2147483648
  3. 0
  4. 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

More C Quizzes