C Programming — Functions
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 100 questions in Functions
Q.1 Hard Functions
In a recursive function implementing factorial calculation, the base case is missing. What is the most likely consequence during execution?
A The program will run infinitely without crashing
B Stack overflow due to infinite recursive calls until memory is exhausted
C The function will automatically return 1 when n becomes 0
D A compile-time error will be generated
Correct Answer:  B. Stack overflow due to infinite recursive calls until memory is exhausted
EXPLANATION

Without a base case, recursion never terminates. Each function call pushes data onto the stack. Eventually, the stack memory is exhausted, causing a stack overflow error. This is a runtime error, not a compile-time error.

Take Test
Q.2 Easy Functions
Consider the function declaration: void func(int x); and later in the code: int result = func(5);. What will be the compilation result?
A Compilation error because func returns void but is assigned to an int variable
B Compilation warning but will compile successfully; result will be undefined
C Successful compilation and result will be 5
D Runtime error will occur
Correct Answer:  A. Compilation error because func returns void but is assigned to an int variable
EXPLANATION

A void function cannot return a value. Attempting to assign the return value of a void function to a variable will cause a compilation error in standard C compilers.

Take Test
Q.3 Medium Functions
A function in C is declared as: int calculate(int *arr, int size). When this function modifies the array elements, what happens to the original array passed from the calling function?
A The original array is modified because arrays are passed by reference
B The original array remains unchanged; only the local copy is modified
C It depends on whether the pointer is declared as const
D The modification only affects the first element of the array
Correct Answer:  A. The original array is modified because arrays are passed by reference
EXPLANATION

In C, arrays decay to pointers when passed to functions, meaning the address is passed. Any modifications through the pointer affect the original array. This is effectively pass-by-reference behavior for arrays.

Take Test
Q.4 Medium Functions
Which of the following demonstrates proper use of the return statement in error handling?
A return NULL; for pointer functions to indicate failure
B return -1; for integer functions to indicate error status
C Use dedicated error codes or special return values to indicate success/failure
D All of the above are valid approaches
Correct Answer:  D. All of the above are valid approaches
EXPLANATION

All three approaches are valid for error handling in C. Functions typically return NULL for pointers, negative values for integers, or use predefined error codes to indicate failure states.

Take Test
Q.5 Hard Functions
In C, what is the relationship between array parameters and pointers in functions?
A Arrays and pointers are identical in function parameters
B Array parameters are automatically converted to pointers to the first element
C Pointers cannot be used where arrays are expected
D Arrays maintain their size information when passed to functions
Correct Answer:  B. Array parameters are automatically converted to pointers to the first element
EXPLANATION

When an array is used as a function parameter, it undergoes array-to-pointer decay, converting to a pointer to the first element. This is why size information is lost.

Take Test
Advertisement
Q.6 Hard Functions
What is a callback function in C?
A A function that returns to the caller immediately
B A function pointer passed as an argument to be invoked later
C A function that calls itself recursively
D A function declared with the callback keyword
Correct Answer:  B. A function pointer passed as an argument to be invoked later
EXPLANATION

A callback is a function pointer passed to another function, which then invokes it at some point. Callbacks are essential for event-driven programming and implementing custom behavior.

Take Test
Q.7 Hard Functions
Which of the following about variadic functions is true?
A They must have at least one fixed parameter before the ellipsis
B They can have only variadic parameters
C Type checking is enforced by the compiler for variadic arguments
D The va_list macro automatically handles type conversion
Correct Answer:  A. They must have at least one fixed parameter before the ellipsis
EXPLANATION

Variadic functions must have at least one fixed parameter before the ellipsis (...). This allows the function to know where variadic arguments begin. Type checking is NOT enforced for variadic arguments.

Take Test
Q.8 Medium Functions
What is the purpose of function inlining in modern C compilers?
A To increase code size for better readability
B To reduce function call overhead by replacing calls with function body
C To prevent function pointers from working
D To enforce external linkage
Correct Answer:  B. To reduce function call overhead by replacing calls with function body
EXPLANATION

Inlining substitutes a function call with the actual function body at compile time, eliminating function call overhead. This is a compiler optimization for performance-critical code.

Take Test
Q.9 Medium Functions
Consider a function that modifies an array passed as a parameter. Which statement is true?
A The array is passed by value, so modifications don't affect the original
B The array decays to a pointer, so modifications affect the original array
C Arrays cannot be modified within functions
D The const qualifier must be used to modify arrays in functions
Correct Answer:  B. The array decays to a pointer, so modifications affect the original array
EXPLANATION

When an array is passed to a function, it decays to a pointer to its first element. This means modifications to array elements affect the original array outside the function.

Take Test
Q.10 Medium Functions
What happens if a function is declared but never defined in C?
A The compiler throws an error immediately
B The program compiles but fails at link time
C The program executes without issues
D The compiler generates a default implementation
Correct Answer:  B. The program compiles but fails at link time
EXPLANATION

If a function is declared but not defined, the compiler generates code to call it (compilation succeeds), but the linker fails to find the function definition, resulting in a linker error.

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