- How to declare, define, and call functions in C
- Formal vs actual parameters, and how arguments are passed
- Return types, void, and the return statement
- Local vs global scope, and the static keyword
- Passing arrays and pointers to functions
- Function prototypes and headers
- Recursion and when to use it
- Common bugs like missing declarations and pass-by-value confusion
This page has 40 multiple choice questions on functions in C. You'll find questions on declarations, definitions, prototypes, parameter passing, return types, scope, static, recursion, and passing arrays and pointers. Each question comes with the correct answer and a short explanation in plain English, so you understand the "why" and not just the "what". These MCQs are useful for beginners preparing for college exams, interviews, or any C programming test. Some questions involve running short code — take them slowly and trace each line.
Function Basics
Q1. Which of the following is a valid return type of a function in C?
Answer: D) All of the above
A function in C can return any type — int, float, char, double, void (nothing), a struct, or even a pointer. The return type tells the compiler what kind of value the function will produce. If a function doesn't return any value, use void. In short, int, float, void, and char are all valid return types — the original answer "A) int" was too restrictive.
Q2. Which symbol is used to call a function in C?
Answer: C) ()
To call a function, write its name followed by parentheses: func();. The parentheses are what actually "invoke" the function — without them, you're just referring to the function name, not calling it. If the function takes arguments, list them inside: add(5, 10);. Braces { } are used to define the body, and * and & have different meanings (pointer dereference and address-of).
Q3. What is a function prototype in C?
Answer: A) A declaration of the function's return type, name, and parameter types
A prototype ends with a semicolon and tells the compiler what the function looks like: int add(int x, int y);. It lets you call the function before its actual definition appears in the file. The definition (with braces and code) is separate; the prototype is just a "heads up" for the compiler.
Q4. How do you call a function in C?
Answer: B) Using the function name followed by parentheses
A function call is simple: write its name, then open and close parentheses with any arguments inside: add(5, 10);. If the function returns a value, you can capture it with assignment: result = add(5, 10);. The other options don't call functions — they either return values or execute something else.
Q5. What is the purpose of main() in C?
Answer: D) To begin execution of the program
Every C program starts running from main() — it's the entry point. The operating system calls main() when your program launches. From there, main() can call other functions to do the work. If you don't have a main(), the linker will complain and the program won't build. That's why every C executable has exactly one main().
Q6. What is the meaning of a parameter in a function?
Answer: B) An input value to the function
A parameter is a variable in the function's definition that receives a value when the function is called. For example, in int add(int x, int y), x and y are parameters. When you call add(5, 10), the values 5 and 10 are arguments — they get copied into the parameters. So parameters are inputs, arguments are the actual values passed in.
Q7. How are arguments passed to a function in C by default?
Answer: B) By value
C is pass-by-value by default: the function receives a copy of each argument. Any change the function makes to its parameters does not affect the original arguments. To simulate pass-by-reference, you pass a pointer — the pointer itself is still passed by value, but it points to the original variable. This is a key C concept and a common exam topic.
Declaration & Definition
Q8. Which keyword is used to declare a function that returns nothing?
Answer: B) void
When a function returns nothing, use void as the return type: void printMessage(). The void keyword means "no type" — the function still does work, it just doesn't send a value back to the caller. define, function, and main are unrelated to return types.
Q9. Which is a valid function declaration in C?
Answer: B) int add(int x, int y);
In C, each parameter must have its own type: int x, int y, not just int x, y. Option A is invalid — it's a common mistake beginners make. Option C has no return type (allowed only in very old C, deprecated). Option D is also valid but the question asks about "int add" specifically — B matches the exact form. In real code, both B and D are valid declarations; the exam answer is B for the int-returning version.
Q10. How do you define a function that takes no arguments in C?
Answer: B) void func(void)
In C, an empty parameter list (func()) technically means "unspecified parameters" — it allows any arguments. To explicitly say "no parameters", use void inside the parentheses: func(void). This is a subtle but important distinction in C, though many modern compilers treat them the same. For strict correctness, option B is the answer.
Q11. Which of the following is a valid function definition in C?
Answer: D) int func(void) { return 0; }
A declaration ends with a semicolon; a definition has a body in curly braces. Options A, B, and C are prototypes (declarations), not definitions. Only option D has the actual body — the code that runs when the function is called. This distinction between "declaration" and "definition" appears in almost every C exam.
Q12. What is a function declaration in C?
Answer: B) To declare the function
A function declaration (also called a prototype) tells the compiler about the function's signature — name, return type, and parameter types — before the function is defined. This lets you call the function earlier in the file. It ends with a semicolon and has no body. It is not the definition (which includes braces and code) and is not a call (which would be func();).
Q13. What is the purpose of a function header in C?
Answer: C) To specify the return type, function name, and parameter list
The "function header" is the first line of a definition — for example, int add(int x, int y). It declares the return type (int), the name (add), and the parameters (int x, int y). The body that follows in braces is the implementation. Together, header + body = a full function definition.
Q14. Which of the following is the correct way to declare a function with no parameters returning void in C?
Answer: D) Both A and B are valid
In practice, both void func() and void func(void) work in modern C compilers. However, strictly speaking, func() means "unspecified parameters" (allows calls with any arguments) while func(void) explicitly means "no parameters". For safety and clarity, prefer void func(void). Option C is invalid syntax. Option D is the correct answer because both A and B will compile.
Parameters & Arguments
Q15. What is the difference between actual parameters and formal parameters in a function?
Answer: A) Formal parameters appear in the function definition; actual parameters appear in the function call
Formal parameters are the placeholder variables in the function definition: in int add(int x, int y), x and y are formal. Actual parameters are the concrete values passed when you call the function: in add(5, 10), 5 and 10 are actual. Remember: formal = definition (the form), actual = call (the actual values).
Q16. Which of the following is an invalid function call?
Answer: B) add(x, y,)
A trailing comma after the last argument is a syntax error in C — the compiler sees an unfinished argument list. Options A, C, and D are all valid calls (D is only valid if the function accepts one parameter). Trailing commas are only valid in array initializers (and even then, only in some contexts), not in function calls.
Q17. What does the const keyword in a parameter declaration do?
Answer: A) It prevents the function from modifying the parameter's value
When a parameter is declared const, the function cannot change its value. For example, void print(const int x) guarantees the function won't modify x. This helps readability — it tells callers "I only read this value, I don't change it." It's especially useful for pointer parameters where you don't want to modify the pointed-to data: const char* s.
Return Types & return Statement
Q18. Why is the return statement used in a function?
Answer: C) To return a value from the function to the caller
The return statement ends the function and sends a value back to the caller. For example, return x + y; in a function typed int means the caller receives that sum. In a void function, return; just ends the function early without sending a value. It's the mechanism that lets functions produce results.
Q19. Which of the following correctly defines a function that returns a float value?
Answer: B) float func(float x)
The first word in a function definition is the return type. To return a float, the function must be declared with float before its name: float func(float x). Option C also returns float but takes an int parameter — the question asks for "returns float", so B is the exact match. Options A and D return void, not float.
Q20. Which correctly declares a function that takes an int parameter and returns a float value?
Answer: B) float func(int x);
The return type comes first (float), then the function name, then the parameter list with its type (int x). So float func(int x); is correct. Option C has it backwards — int return type, float parameter. Options A and D return void. Reading a function declaration left to right gives you "returns float, takes int".
Q21. What is the use of the return type in a function?
Answer: C) To specify the type of value returned by the function
The return type tells the compiler (and readers) what kind of value the function produces. int func() returns an integer, float func() returns a float, and void func() returns nothing. Getting the return type right matters — if it doesn't match what the function actually returns, the compiler will warn or error.
Q22. Which correctly declares a function that returns int and takes no parameters?
Answer: D) int func(void)
For strict "returns int, takes no parameters" semantics in C, use int func(void). Option B (int func()) is technically also valid but means "takes unspecified parameters" in older C. For an exam, D is the safest answer because void in the parameter list explicitly says "no arguments". Both A and C return void (not int), so they're wrong.
Q23. What does void mean in a function declaration?
Answer: C) The function either returns nothing (as return type) or takes no parameters (in the parameter list)
The void keyword is used in two places with related meanings. As a return type — void func() — it means "returns nothing". In the parameter list — int func(void) — it means "takes no parameters". Same keyword, two contexts, both meaning "nothing". C has no notion of "private" functions in the way C++ or Java do (except with static linkage).
Scope & static Keyword
Q24. The scope of a variable declared inside a function is ______.
Answer: A) Local to the function
A variable declared inside a function body is local — it exists only while that function runs, and other functions cannot see it. This is the default behaviour (also called "automatic" storage). "Static" is a separate storage class (option C is a different concept). The exam asks about scope, so local is the answer.
Q25. What is the use of the static keyword in a C function?
Answer: C) To preserve the value of a variable between function calls, or to limit the function's visibility to the file
The static keyword has two uses in C. Applied to a local variable inside a function, static means the variable keeps its value between calls (not reset each time). Applied to a function (or global variable), static limits its visibility to the file it's declared in. Both uses are important — the exam answer C covers both. "Private" and "public" are C++/Java concepts, not C.
Q26. What is the scope of a variable declared in the main() function?
Answer: A) Local to the main() function
main() is just a function like any other, and variables declared inside it are local to it. You cannot access a variable from main() in another function unless you pass it as an argument or make it global. This surprises some beginners who assume main() is somehow "special" — it's just the entry point, not a special scope.
Functions with Pointers & Arrays
Q27. What is the meaning of the following function prototype?
void docalculation(int x, int y, int* sum, int* diff);
Answer: A) The function takes two input parameters and returns two output parameters via pointers
The function takes x and y as inputs (by value) and takes two pointers (sum and diff) as output parameters. When called, the caller passes the addresses of two variables, and the function writes the sum and difference into them. This is C's standard idiom for "returning multiple values" from a function. Option D is close but misses the point — the function also writes results through pointers.
Q28. Which correctly defines a function that takes an int pointer as a parameter?
Answer: A) void func(int* x)
The asterisk after int means "pointer to int": int* x or int *x. Option A declares a void function taking an int pointer. Option D also takes an int pointer but returns int — the question asks about "takes int pointer", and A matches the simplest interpretation. Both A and D are technically correct; A is the cleanest match because it introduces no extra return-value concept.
Q29. Can a C function return multiple values directly?
Answer: B) No, but you can simulate it using pointer parameters or a struct
C functions return exactly one value — that's the language rule. But you can achieve "multiple return values" in two common ways: (1) pass pointers for the extra outputs, so the function writes into them, or (2) return a struct that packs several values together. Option A is wrong — return x, y; uses the comma operator and only returns y, which is a classic bug.
Program Output Questions
Q30. What is the output of the following program?
int square(int x) {
return x * x;
}
int main() {
int result = square(5);
printf("%d", result);
return 0;
}
Answer: B) 25
square(5) returns 5 × 5 = 25, which gets stored in result and printed. If you answered 10, you might have been thinking of 5 × 2 — but the function squares its input, not doubles it. This is the simplest function-output pattern and appears in nearly every C exam.
Q31. What is the output of the following program?
int add(int x, int y) {
return x + y;
}
int main() {
printf("%d", add(5, 10));
return 0;
}
Answer: C) 15
add(5, 10) returns 5 + 10 = 15, which is printed directly. Note that the function has a return type of int — not void — so it produces a value. If you answered 50, you multiplied the arguments instead of adding them; if you answered 5 or 10, you thought only one argument was used.
Q32. What is the output of the following program?
#include <stdio.h>
void printHello() {
printf("Hello");
}
int main() {
printHello();
return 0;
}
Answer: A) Hello
printHello() prints "Hello" and returns nothing (it's a void function). main() calls it and then returns 0. So the only output is "Hello". Option D is tempting — the return 0 in main() does not print anything; it's the exit code. Return values are silent; only printf produces visible output.
Q33. What is the output of the following program?
#include <stdio.h>
int cube(int p) {
return p * p * p;
}
int main() {
printf("%d", cube(3));
return 0;
}
Answer: D) 27
cube(3) = 3 × 3 × 3 = 27. Option B (6) is 3 × 2, option C (9) is 3 × 3 — both are partial multiplications. The function multiplies p three times, which gives 27. This tests whether you read the function body carefully — p * p * p vs p * p is a one-character difference with a big result.
Q34. What is the output of the following program?
#include <stdio.h>
void greet(char name[]) {
printf("Hello, %s!\n", name);
}
int main() {
char name[20] = "Alice";
greet(name);
return 0;
}
Answer: B) Hello, Alice!
The greet() function receives the array name (which decays to a pointer to the first char) and prints it using %s. Since name holds "Alice", the printf substitutes Alice into the format string. This demonstrates passing arrays (and strings) to functions — the array's contents are what get used, not the variable name itself.
Q35. What is the output of the following program?
#include <stdio.h>
void modify(int x) {
x = 100;
}
int main() {
int a = 5;
modify(a);
printf("%d", a);
return 0;
}
Answer: A) 5
This is the classic pass-by-value demonstration. modify() receives a copy of a, sets that copy to 100, and returns. The original a in main() is untouched. So a stays 5. To actually change a, modify would need to take int* x and dereference it — a very common exam question.
Q36. What is the output of the following program?
#include <stdio.h>
void modify(int* x) {
*x = 100;
}
int main() {
int a = 5;
modify(&a);
printf("%d", a);
return 0;
}
Answer: B) 100
This time, modify takes a pointer (int* x) and main passes the address of a (&a). Inside modify, *x = 100 writes 100 to the address that x points to — which is a's memory. So a becomes 100. This is the pass-by-pointer idiom that simulates pass-by-reference in C — the key difference from Q35.
Recursion & Advanced Concepts
Q37. What is recursion in C?
Answer: C) A function that calls itself
Recursion is when a function calls itself to solve smaller versions of the same problem. Classic examples: factorial, Fibonacci, tree traversal. Every recursive function needs a base case (a condition that stops the recursion), otherwise it runs forever and causes a stack overflow.
Q38. What is the default return type of a function in C if none is specified?
Answer: B) int (in older C standards; modern C requires explicit types)
In the original C (pre-C99), a function declared without a return type defaulted to int. This "implicit int" rule was removed in C99 — modern C compilers warn or error if you omit a return type. For exam questions based on older material, "int" is the answer; but always write explicit return types in real code for clarity and portability.
Q39. What is the main benefit of using functions in C?
Answer: B) They promote code reuse, modularity, and easier testing
Functions let you break a big problem into smaller, testable pieces. You write logic once and call it from anywhere — no duplication. Each function can be tested independently. This is the foundation of modular programming, which is why every real C program (and every other language) uses functions heavily. They don't slow programs down (option A); in fact well-factored code often runs faster.
Q40. What is the difference between a function declaration and a function definition in C?
Answer: B) A declaration has no body (just the signature); a definition includes the body
A declaration (prototype) tells the compiler what the function looks like — int add(int x, int y); — and ends with a semicolon. A definition provides the actual code — int add(int x, int y) { return x + y; } — with braces and statements. You can declare a function many times in a program, but you can only define it once. This split is what allows multi-file C programs to work.
Frequently Asked Questions
What is the difference between function declaration and function definition in C?
A declaration (prototype) tells the compiler the function's name, return type, and parameter types, ending with a semicolon. A definition provides the actual body of the function with code inside braces. You can declare a function many times but define it only once. This split is what lets multi-file C programs work.
Why are function prototypes important in C?
A prototype lets the compiler check that your calls match the expected argument types and count. Without it, the compiler may allow incorrect calls, leading to undefined behaviour at runtime. Prototypes also let you call a function before its definition appears in the file — essential for organizing large programs.
What is the difference between pass by value and pass by reference in C?
C passes all arguments by value by default — the function gets a copy. To simulate pass by reference, pass a pointer to the variable. Changes to the pointer's target affect the original variable; changes to a by-value parameter do not. This is why functions that modify their inputs take pointer parameters.
What does the static keyword do when applied to a function in C?
When applied to a function, static limits its visibility to the file it's defined in. This is called internal linkage. The function cannot be called from other source files, even if they're linked together. Applied to a local variable inside a function, static preserves its value between calls. Both uses are common in real C code.
What is recursion, and when should I avoid it?
Recursion is when a function calls itself to solve smaller sub-problems. It's elegant for tree traversal, factorial, Fibonacci, and divide-and-conquer algorithms. But it uses stack memory for each call, so deep recursion can cause a stack overflow. Prefer iteration when the recursion depth could be large or performance is critical.
💡 Tip: Functions are the backbone of every C program — they're tested heavily in exams and interviews. Master the split between declaration and definition, and understand pass-by-value vs pass-by-pointer cold. That single distinction appears in dozens of questions.