How does the volatile keyword affect function behavior in C?
Answer: B
The volatile keyword tells the compiler not to optimize away variable accesses, ensuring the variable is read from memory each time.
Q.322Medium
Which of the following is a valid function pointer initialization?
Answer: D
Both forms are valid. Functions decay to function pointers, so both &printf and printf assign the function address correctly.
Q.323Easy
Which storage class specifier allows a function to be called only within the file where it is defined?
Answer: A
The static keyword restricts function scope to the file in which it is declared, preventing external linkage.
Q.324Easy
What is the return type of a function that performs an action but doesn't return any value?
Answer: B
The void keyword is used as return type for functions that do not return any value.
Q.325Easy
In C, what happens when a function is called before its declaration?
Answer: B
C requires function declaration before use (forward declaration or definition). Calling without prior declaration causes compilation error in modern C standards.
Advertisement
Q.326Easy
Which of the following is an example of call by value in C?
Answer: B
Call by value passes a copy of the variable. Changes inside the function don't affect the original variable. Option B demonstrates this principle.
Q.327Easy
What is the main difference between function declaration and function definition?
Answer: A
Declaration (prototype) informs compiler about function signature; definition provides the actual implementation body.
Q.328Medium
Consider the code: int calculate(int a, int b = 5) { return a + b; }. What is the issue?
Answer: B
Default parameters are a C++ feature, not available in standard C. C requires explicit arguments for all parameters.
Q.329Medium
What will be the output of this recursive function? int fact(int n) { if(n <= 1) return 1; return n * fact(n-1); } fact(5)
Answer: C
This calculates factorial. fact(5) = 5*4*3*2*1 = 120. Base case n<=1 stops recursion.
Q.330Medium
Which statement about function parameters passed as arrays is correct?
Answer: B
Arrays in C decay to pointers to their first element, effectively making them pass-by-reference. Changes inside function affect original array.
Q.331Medium
What is the purpose of the 'extern' keyword when used with a function?
Answer: A
extern allows you to declare a function defined elsewhere, enabling its use across multiple translation units.
Q.332Medium
Consider: void modify(int *ptr) { *ptr = 20; } int main() { int x = 10; modify(&x); printf("%d", x); }. Output?
Answer: B
This is call by reference using pointers. The function receives address of x, dereferences and modifies it to 20.
Q.333Medium
What does variadic function mean in C?
Answer: A
Variadic functions accept variable number of arguments using ellipsis (...) and accessed with va_list, va_arg macros.
Q.334Medium
Which of the following correctly demonstrates inline function usage for optimization?
Answer: B
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.
Q.335Hard
What will happen if a recursive function has no base case?
Answer: B
Without base case, recursion never stops, causing stack to overflow as return addresses keep accumulating.
Q.336Hard
Consider mutual recursion: void funcA(int n); void funcB(int n); funcA calls funcB and vice versa. What is required?
Answer: A
For mutual recursion, you need forward declaration (prototype) of at least one function before it's called by another.
Q.337Hard
What is the correct way to return multiple values from a function in C?
Answer: D
C doesn't support multiple return values. Both pointers (call-by-reference) and structs are valid techniques.
Q.338Hard
Analyze: int (*funcPtr)(int, int); What does this declaration represent?
Answer: B
The syntax (*funcPtr) indicates funcPtr is a pointer. It points to functions taking two ints and returning int.
Q.339Medium
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); }
Answer: B
This is call-by-value. The function swaps copies of x and y, not the originals. Original values remain unchanged.
Q.340Hard
In C99 standard, what is true about function declarations at block scope?
Answer: B
C99 allows function declarations within blocks; they have scope limited to that block. This is different from function definitions which remain at file scope.