Home Subjects C Programming Functions

C Programming
Functions

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 100
Topics in C Programming
Q.31 Medium Functions
What is the primary advantage of using inline functions?
A They save memory by reducing code duplication
B They eliminate function call overhead by substituting code at call site
C They enable recursion without stack overflow
D They improve code readability
Correct Answer:  B. They eliminate function call overhead by substituting code at call site
EXPLANATION

Inline functions request the compiler to replace function calls with actual function code, eliminating call overhead. However, compiler may ignore inline suggestion.

Take Test
Q.32 Medium Functions
Which of the following is true about function pointers in C?
A They cannot point to built-in functions
B They enable dynamic function calls and callbacks
C They require special declaration syntax different from regular pointers
D They cannot be stored in arrays
Correct Answer:  B. They enable dynamic function calls and callbacks
EXPLANATION

Function pointers are powerful features enabling dynamic function selection at runtime, crucial for callbacks, function arrays, and design patterns like strategy pattern.

Take Test
Q.33 Easy Functions
What is the output of this recursive function?
int fact(int n) { if(n
A 24
B 10
C 12
D Stack overflow
Correct Answer:  A. 24
EXPLANATION

fact(4) = 4*fact(3) = 4*3*fact(2) = 4*3*2*fact(1) = 4*3*2*1 = 24. This is a proper factorial implementation with correct base case.

Take Test
Q.34 Medium Functions
Analyze the following pointer to function declaration: int (*ptr)(int, int);
A ptr is a function that returns int pointer
B ptr is a pointer to a function taking two int parameters and returning int
C ptr is an array of function pointers
D ptr is a function returning array of ints
Correct Answer:  B. ptr is a pointer to a function taking two int parameters and returning int
EXPLANATION

The parentheses around (*ptr) indicate ptr is a pointer. The remaining (int, int) shows it points to a function taking two int arguments and returning int.

Take Test
Q.35 Medium Functions
What is the difference between call by value and call by reference in C?
A Call by reference creates a copy; call by value passes address
B Call by value passes copy; call by reference passes address via pointers
C No difference; C uses only call by value
D Call by reference is faster
Correct Answer:  B. Call by value passes copy; call by reference passes address via pointers
EXPLANATION

C supports call by value (default) and call by reference (using pointers). Call by value passes a copy; call by reference passes the address allowing modifications to original.

Take Test
Q.36 Easy Functions
What will be the output of the following code?
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(5, add(3, 2))); return 0; }
A 10
B 8
C Compilation error
D 5
Correct Answer:  A. 10
EXPLANATION

Inner add(3,2) returns 5, then add(5,5) returns 10. Functions can be nested in arguments as long as return type matches parameter type.

Take Test
Q.37 Medium Functions
Which calling convention passes parameters through the stack from right to left?
A cdecl
B stdcall
C fastcall
D pascal
Correct Answer:  A. cdecl
EXPLANATION

The cdecl (C declaration) calling convention is the standard in C, pushing parameters onto the stack from right to left, with the caller responsible for stack cleanup.

Take Test
Q.38 Medium Functions
What is the scope of a static variable declared inside a function?
A Local to the function, but retains value between calls
B Global scope with external linkage
C Only valid during function execution
D Accessible to all functions in the program
Correct Answer:  A. Local to the function, but retains value between calls
EXPLANATION

Static variables inside a function have local scope but static storage duration, meaning they retain their value between function calls and are initialized only once.

Take Test
Q.39 Medium Functions
In C, how many parameters can a function have at maximum?
A Up to 32 parameters
B Up to 127 parameters
C No predefined limit in C standard
D Only 8 parameters
Correct Answer:  C. No predefined limit in C standard
EXPLANATION

The C standard does not impose a maximum limit on the number of function parameters, though practical implementations may have compiler-specific limits.

Take Test
Q.40 Easy Functions
What happens when a function is called without a return statement reaching the end?
A Compilation error occurs
B An undefined/garbage value is returned
C 0 is automatically returned
D NULL is returned
Correct Answer:  B. An undefined/garbage value is returned
EXPLANATION

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.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips