C Functions Quiz — 15 Questions with Answers

Test your understanding of C functions with these 15 multiple-choice questions — pass by value, function pointers, recursion, and static local variables. 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 15 (Easy)

How are arguments passed to functions in C by default?

  1. By value
  2. By reference
  3. By name
  4. By pointer automatically
Show answer

Answer: A — By value

C always passes arguments by value — the function receives a copy. To modify a caller's variable you pass a pointer to it.

Question 2 of 15 (Easy)

What return type indicates that a function returns no value?

  1. null
  2. void
  3. int
  4. empty
Show answer

Answer: B — void

'void' as a return type means the function does not return a value.

Question 3 of 15 (Medium)

What is most likely to happen if a recursive function has no base case?

  1. It returns 0
  2. Infinite recursion and a stack overflow
  3. A compile error
  4. It runs exactly once
Show answer

Answer: B — Infinite recursion and a stack overflow

Without a base case the recursion never stops, consuming stack frames until the stack overflows and the program crashes.

Question 4 of 15 (Hard)

What is printed if f() is called three times in a row?

void f(void) {
    static int c = 0;
    c++;
    printf("%d", c);
}
  1. 000
  2. 111
  3. 123
  4. 333
Show answer

Answer: C — 123

A static local variable keeps its value between calls and is initialized only once. c becomes 1, then 2, then 3 — printing 123.

Full walkthrough with compilable code: read the detailed explanation.

Question 5 of 15 (Medium)

What is the output of this code?

int add(int a, int b) { return a + b; }
printf("%d", add(3, 4));
  1. 7
  2. 34
  3. 0
  4. Compile error
Show answer

Answer: A — 7

add receives copies of 3 and 4, computes 3 + 4 = 7, and returns it. printf prints 7.

Full walkthrough with compilable code: read the detailed explanation.

Question 6 of 15 (Hard)

What is the output of this code?

void inc(int x) { x++; }
int n = 5;
inc(n);
printf("%d", n);
  1. 6
  2. 5
  3. Compile error
  4. Undefined behavior
Show answer

Answer: B — 5

C passes by value. inc receives a copy of n and increments the copy. n in the caller remains 5.

Full walkthrough with compilable code: read the detailed explanation.

Question 7 of 15 (Medium)

What is a function prototype used for?

  1. To allocate memory for the function
  2. To declare a function's return type and parameter types before its definition
  3. To call the function
  4. To define the function body
Show answer

Answer: B — To declare a function's return type and parameter types before its definition

A function prototype (declaration) tells the compiler the function's return type and parameter types so it can type-check calls before seeing the full definition.

Question 8 of 15 (Hard)

What does the 'inline' keyword hint to the compiler?

  1. The function must be inlined — it is mandatory
  2. The function body should be substituted at call sites to avoid call overhead
  3. The function is recursive
  4. The function has no side effects
Show answer

Answer: B — The function body should be substituted at call sites to avoid call overhead

'inline' is a hint — the compiler may choose to substitute the function body at each call site, eliminating call overhead. It is not a mandate; the compiler can ignore it.

Question 9 of 15 (Easy)

Which header must you include to use printf?

  1. stdlib.h
  2. stdio.h
  3. string.h
  4. math.h
Show answer

Answer: B — stdio.h

printf and other standard I/O functions are declared in <stdio.h>.

Question 10 of 15 (Hard)

What does this function pointer call do?

int add(int a, int b) { return a + b; }
int (*op)(int, int) = add;
printf("%d", op(3, 4));
  1. Compile error
  2. 7
  3. 34
  4. Undefined behavior
Show answer

Answer: B — 7

op is a function pointer assigned to add. op(3, 4) calls add(3, 4) which returns 7.

Question 11 of 15 (Medium)

What does 'static' mean when applied to a function?

  1. The function is called once
  2. The function has internal linkage — it is not visible outside its translation unit
  3. The function's local variables persist between calls
  4. The function cannot be recursive
Show answer

Answer: B — The function has internal linkage — it is not visible outside its translation unit

A 'static' function has internal linkage: it can only be called from within the same .c file. This is a common way to make helper functions private.

Question 12 of 15 (Hard)

What is variadic function support in C, and what header enables it?

  1. Functions with variable return types; <typedefs.h>
  2. Functions accepting a variable number of arguments; <stdarg.h>
  3. Functions that vary their behavior at runtime; <stdlib.h>
  4. Recursive functions with variable depth; <setjmp.h>
Show answer

Answer: B — Functions accepting a variable number of arguments; <stdarg.h>

C supports variadic functions (like printf) that accept a variable number of arguments. <stdarg.h> provides va_list, va_start, va_arg, and va_end to access the extra arguments.

Question 13 of 15 (Medium)

What is the purpose of 'argc' in 'int main(int argc, char *argv[])'?

  1. The number of bytes in argv
  2. The count of command-line arguments (including the program name)
  3. The return code of the last system call
  4. The size of the program
Show answer

Answer: B — The count of command-line arguments (including the program name)

argc (argument count) is the number of command-line arguments passed to the program. argv[0] is the program name, so argc is at least 1.

Question 14 of 15 (Easy)

What does the 'return' statement do in a function?

  1. Jumps to the next function
  2. Exits the function and optionally returns a value to the caller
  3. Restarts the function from the beginning
  4. Exits the program
Show answer

Answer: B — Exits the function and optionally returns a value to the caller

return exits the current function and passes a value back to the caller. In void functions, return can be used without a value.

Question 15 of 15 (Hard)

What is the output of this code?

int fact(int n) {
    return n <= 1 ? 1 : n * fact(n - 1);
}
printf("%d", fact(5));
  1. 60
  2. 120
  3. 24
  4. Compile error
Show answer

Answer: B — 120

fact(5) = 5 * 4 * 3 * 2 * 1 = 120.

Full walkthrough with compilable code: read the detailed explanation.

How Did You Score?

All 15 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