Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

198 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 131–140 of 198
Topics in C Programming
Q.131 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.132 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.133 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.134 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.135 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.136 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.137 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.138 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.139 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.140 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
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