Home Subjects C Programming Functions

C Programming
Functions

C language from basics to advanced placement prep

24 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 24
Topics in C Programming
Q.11 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.

Test
Q.12 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.

Test
Q.13 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.

Test
Q.14 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.

Test
Q.15 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.

Test
Q.16 Hard Functions
How does the volatile keyword affect function behavior in C?
A It makes functions execute faster
B It prevents compiler optimization of variable accesses
C It changes function calling convention
D It has no effect on functions
Correct Answer:  B. It prevents compiler optimization of variable accesses
EXPLANATION

The volatile keyword tells the compiler not to optimize away variable accesses, ensuring the variable is read from memory each time.

Test
Q.17 Hard Functions
What is the primary advantage of using function pointers in C?
A Faster execution than direct function calls
B Dynamic function selection at runtime
C Automatic memory management
D Better code readability
Correct Answer:  B. Dynamic function selection at runtime
EXPLANATION

Function pointers enable runtime polymorphism by allowing selection of which function to call based on runtime conditions.

Test
Q.18 Hard Functions
In C99 and later standards, what is the maximum number of parameters a function can have?
A 255
B 256
C 127
D No fixed limit in standard, but implementation-dependent
Correct Answer:  D. No fixed limit in standard, but implementation-dependent
EXPLANATION

While C99 guarantees support for at least 127 parameters, the actual limit is implementation-dependent and varies by compiler.

Test
Q.19 Hard Functions
What is function overloading in the context of C?
A C supports function overloading like C++
B C does not support function overloading; you must use different function names or variadic functions
C It means calling the same function multiple times
D It is a deprecated feature in modern C
Correct Answer:  B. C does not support function overloading; you must use different function names or variadic functions
EXPLANATION

C does not support function overloading. To achieve similar functionality, use different names or variadic functions (using ...) or union of function pointers.

Test
Q.20 Hard Functions
Which of the following is TRUE about inline functions in C99 standard?
A They are mandatory keywords
B They are hints to the compiler to expand function code inline
C They eliminate the need for function declarations
D They cannot have parameters
Correct Answer:  B. They are hints to the compiler to expand function code inline
EXPLANATION

The 'inline' keyword is a hint to the compiler to replace function calls with the function body, reducing overhead but increasing code size.

Test
IGET
IGET AI
Online · Exam prep assistant
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