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 41–50 of 100
Topics in C Programming
Q.41 Easy Functions
Which of the following is a valid function declaration in C?
A int func(void);
B func int();
C void int func();
D int func() void;
Correct Answer:  A. int func(void);
EXPLANATION

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.

Take Test
Q.42 Easy Functions
What is the primary purpose of function prototypes in C?
A To declare the function signature before its definition
B To allocate memory for function variables
C To optimize function execution speed
D To prevent function from being called
Correct Answer:  A. To declare the function signature before its definition
EXPLANATION

Function prototypes inform the compiler about function name, return type, and parameters before the actual definition, enabling proper type checking during compilation.

Take Test
Q.43 Hard Functions
Which approach is more efficient for passing large structures to functions?
A Pass by value (entire structure copied)
B Pass by pointer (only address passed)
C Pass by reference (not available in C)
D Use extern to share globally
Correct Answer:  B. Pass by pointer (only address passed)
EXPLANATION

Passing large structures by pointer is more efficient as only address (typically 4-8 bytes) is copied, not entire structure.

Take Test
Q.44 Hard Functions
In C99 standard, what is true about function declarations at block scope?
A Functions cannot be declared inside blocks
B Function declarations inside blocks have local scope
C Such declarations are only valid with extern keyword
D Block scope declarations create implicit static storage
Correct Answer:  B. Function declarations inside blocks have local scope
EXPLANATION

C99 allows function declarations within blocks; they have scope limited to that block. This is different from function definitions which remain at file scope.

Take Test
Q.45 Medium Functions
What is the output of this code? void swap(int a, int b) { int temp = a; a = b; b = temp; } int main() { int x = 5, y = 10; swap(x, y); printf("%d %d", x, y); }
A 10 5
B 5 10
C 0 0
D Garbage values
Correct Answer:  B. 5 10
EXPLANATION

This is call-by-value. The function swaps copies of x and y, not the originals. Original values remain unchanged.

Take Test
Q.46 Hard Functions
Analyze: int (*funcPtr)(int, int); What does this declaration represent?
A A function that takes two integers and returns pointer
B A pointer to function taking two integers returning int
C Array of function pointers
D A structure containing function pointer
Correct Answer:  B. A pointer to function taking two integers returning int
EXPLANATION

The syntax (*funcPtr) indicates funcPtr is a pointer. It points to functions taking two ints and returning int.

Take Test
Q.47 Hard Functions
What is the correct way to return multiple values from a function in C?
A return a, b, c; // Multiple return values
B Use pointers as output parameters
C Use struct to bundle values and return struct
D Both B and C are correct approaches
Correct Answer:  D. Both B and C are correct approaches
EXPLANATION

C doesn't support multiple return values. Both pointers (call-by-reference) and structs are valid techniques.

Take Test
Q.48 Hard Functions
Consider mutual recursion: void funcA(int n); void funcB(int n); funcA calls funcB and vice versa. What is required?
A Forward declaration of at least one function
B Both functions must be defined before any call
C Mutual recursion is not allowed in C
D Extra extern keyword for both functions
Correct Answer:  A. Forward declaration of at least one function
EXPLANATION

For mutual recursion, you need forward declaration (prototype) of at least one function before it's called by another.

Take Test
Q.49 Hard Functions
What will happen if a recursive function has no base case?
A Compiler error
B Stack overflow at runtime
C Function returns NULL
D Infinite loop continues forever
Correct Answer:  B. Stack overflow at runtime
EXPLANATION

Without base case, recursion never stops, causing stack to overflow as return addresses keep accumulating.

Take Test
Q.50 Medium Functions
Which of the following correctly demonstrates inline function usage for optimization?
A inline void process() { } // Always inlined
B inline int square(int x) { return x*x; } // Compiler may inline
C void inline() { } // Syntax error
D Inline functions are not part of C standard
Correct Answer:  B. inline int square(int x) { return x*x; } // Compiler may inline
EXPLANATION

inline is a hint to compiler to expand function at call site. It's supported in C99+ and compiler decides whether to inline or not.

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