C Programming — Functions
C language from basics to advanced placement prep
24 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 24 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 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
Q.3 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.4 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.5 Hard Functions
In the context of function pointers, what does the restrict keyword do?
A Restricts the pointer from pointing to different functions
B Tells the compiler that the pointer is the only way to access the data
C Makes the function inaccessible from other files
D Prevents pointer arithmetic
Correct Answer:  B. Tells the compiler that the pointer is the only way to access the data
EXPLANATION

The restrict keyword informs the compiler that the pointer is the sole means of accessing the data it points to, allowing for optimization. It's a hint for compiler optimization.

Take Test
Advertisement
Q.6 Hard Functions
How are function arguments evaluated in C?
A Left to right (guaranteed order)
B Right to left (guaranteed order)
C The order is unspecified and implementation-dependent
D Based on the function's parameter list order
Correct Answer:  C. The order is unspecified and implementation-dependent
EXPLANATION

The C standard does not specify the order of evaluation of function arguments. The order is implementation-dependent and can vary between compilers.

Take Test
Q.7 Hard Functions
What happens when a function with variadic parameters is called with fewer arguments than expected?
A Compilation error occurs
B Remaining arguments are initialized to 0
C Undefined behavior - garbage values are read
D Function call is rejected at runtime
Correct Answer:  C. Undefined behavior - garbage values are read
EXPLANATION

Variadic functions (using ...) don't validate argument count. Calling with fewer arguments leads to undefined behavior as the function reads undefined values from stack.

Take Test
Q.8 Hard Functions
What will this code output?
int x = 10;
int* getAddress() { return &x; }
main() { int *ptr = getAddress(); printf("%d", *ptr); }
A 10
B Address of x
C Undefined behavior (dangling pointer would occur if x was local)
D Compilation error
Correct Answer:  A. 10
EXPLANATION

Since x is static (global scope), returning its address is safe and the pointer remains valid. The output is 10. If x were local, it would be undefined behavior.

Take Test
Q.9 Hard Functions
What does the restrict keyword do when used with pointer parameters in C99?
A Prevents the pointer from being modified
B Tells compiler that pointer is not aliased, enabling optimizations
C Restricts pointer to point only to local variables
D Makes pointer read-only
Correct Answer:  B. Tells compiler that pointer is not aliased, enabling optimizations
EXPLANATION

The restrict keyword (C99) is a promise to the compiler that the pointer is the only way to access that memory during its lifetime, allowing aggressive optimizations.

Take Test
Q.10 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
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