C questions in placement tests and university exams are rarely about syntax alone. Most of what you will find here is output prediction, pointer arithmetic, arrays and strings, structures and unions, storage classes, recursion, and file handling. The explanations walk through memory behaviour step by step, which is usually where the confusion sits rather than in the code itself.
What is the primary purpose of using functions in C programming?
Answer: A
Functions allow code reusability, modularity, and easier maintenance. They break down complex problems into smaller, manageable pieces.
Q.2Easy
Which keyword is used to define a function in C?
Answer: C
In C, functions are defined by specifying the return type followed by the function name and parameters. No specific 'function' keyword is used.
Q.3Easy
Which of the following is a correct function declaration?
Answer: A
Function declaration syntax is: return_type function_name(parameter_list);
Q.4Easy
What will be the output of the following code? int func(int x) { return x * 2; } int main() { printf("%d", func(5)); }
Answer: B
func(5) returns 5 * 2 = 10, which is then printed.
Q.5Easy
How many times can a function be called in a C program?
Answer: C
A function can be called as many times as needed within a program, limited only by memory and stack constraints.
Q.6Easy
What is the return type of the strlen() function in C?
Answer: B
strlen() returns size_t, which is an unsigned integer type used to represent sizes and counts in C.
Q.7Easy
What is the scope of a function parameter in C?
Answer: C
Function parameters have function scope, meaning they are accessible throughout the entire function body.
Q.8Easy
Which keyword is used to create a function that can be expanded inline by the compiler without actual function call overhead?
Answer: C
The 'inline' keyword (introduced in C99) suggests to the compiler to replace function calls with actual code, reducing call overhead.
Q.9Easy
Consider: int func(int x) { return ++x; } What is the difference if we use x++ instead of ++x?
Answer: B
Pre-increment (++x) increments and returns the new value, while post-increment (x++) increments but returns the old value.
Q.10Easy
What is the output of: int add(int a, int b) { int result = a + b; return result; } If called as add(5, 3)?
Answer: A
The function simply adds two integers and returns their sum, which is 5 + 3 = 8.
Q.11Easy
What will be the output? int func(int *p) { return *p; } int main() { int x = 10; printf("%d", func(&x)); }
Answer: A
The function receives a pointer to x, dereferences it with *p, and returns the value 10.
Q.12Easy
In the context of recursion, which of the following is essential to avoid infinite recursion?
Answer: B
A base case is essential in recursive functions to provide a termination condition, otherwise the function will recurse infinitely.
Q.13Easy
Which storage class specifier allows a function to be called only within the file where it is defined?
Answer: A
The static keyword restricts function scope to the file in which it is declared, preventing external linkage.
Q.14Easy
What is the return type of a function that performs an action but doesn't return any value?
Answer: B
The void keyword is used as return type for functions that do not return any value.
Q.15Easy
In C, what happens when a function is called before its declaration?
Answer: B
C requires function declaration before use (forward declaration or definition). Calling without prior declaration causes compilation error in modern C standards.
Q.16Easy
Which of the following is an example of call by value in C?
Answer: B
Call by value passes a copy of the variable. Changes inside the function don't affect the original variable. Option B demonstrates this principle.
Q.17Easy
What is the main difference between function declaration and function definition?
Answer: A
Declaration (prototype) informs compiler about function signature; definition provides the actual implementation body.
Q.18Easy
What is the primary purpose of function prototypes in C?
Answer: A
Function prototypes inform the compiler about function name, return type, and parameters before the actual definition, enabling proper type checking during compilation.
Q.19Easy
Which of the following is a valid function declaration in C?
Answer: A
The correct syntax is return_type function_name(parameters). Option A follows proper C syntax with int as return type, func as name, and void indicating no parameters.
Q.20Easy
What happens when a function is called without a return statement reaching the end?
Answer: B
If a non-void function doesn't explicitly return a value, it returns whatever garbage value happens to be in the return register, leading to undefined behavior.