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.62Hard
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.
Q.63Hard
Which approach is more efficient for passing large structures to functions?
Answer: B
Passing large structures by pointer is more efficient as only address (typically 4-8 bytes) is copied, not entire structure.
Q.64Hard
What does the restrict keyword do when used with pointer parameters in C99?
Answer: B
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.
Q.65Hard
What will this code output?
int x = 10;
int* getAddress() { return &x; }
main() { int *ptr = getAddress(); printf("%d", *ptr); }
Answer: A
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.
Advertisement
Q.66Hard
What happens when a function with variadic parameters is called with fewer arguments than expected?
Answer: C
Variadic functions (using ...) don't validate argument count. Calling with fewer arguments leads to undefined behavior as the function reads undefined values from stack.
Q.67Hard
How are function arguments evaluated in C?
Answer: C
The C standard does not specify the order of evaluation of function arguments. The order is implementation-dependent and can vary between compilers.
Q.68Hard
In the context of function pointers, what does the restrict keyword do?
Answer: B
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.
Q.69Hard
Which of the following about variadic functions is true?
Answer: A
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.
Q.70Hard
What is a callback function in C?
Answer: B
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.
Q.71Hard
In C, what is the relationship between array parameters and pointers in functions?
Answer: B
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.
Q.72Hard
In a recursive function implementing factorial calculation, the base case is missing. What is the most likely consequence during execution?
Answer: B
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.
Q.73Hard
Consider a 2D array int matrix[3][3]. If we access matrix as a 1D array, how many total elements can we access?
Answer: C
2D array is stored contiguously in memory. 3x3 array has 9 elements total, accessible as a 1D array of 9 elements.
Q.74Hard
Consider: int arr[3][4][5]. What is the size of arr[0][0]?
Answer: A
arr[0][0] is a 1D array of 5 integers. Each int is 4 bytes, so total is 5×4=20 bytes.
Q.75Hard
Which of the following is true about strcpy(dest, src)?
Answer: B
strcpy() doesn't check dest buffer size, making it unsafe. It can cause buffer overflow if src is larger than dest. Modern compilers recommend strncpy() or strlcpy().
Q.76Hard
What is the main difference between char arr[] = "Test" and char *ptr = "Test"?
Answer: A
arr creates a modifiable array copy of the string. ptr points to a string literal (read-only in memory). Modifying *ptr leads to undefined behavior.
Q.77Hard
If ptr is a pointer to int array and ptr = arr, what does ptr[3] represent?
Answer: D
ptr[3] is equivalent to arr[3] and accesses the element at address *(ptr+3). For int*, ptr+3 moves 12 bytes (3×4 bytes) in memory.
Q.78Hard
What is the correct way to safely copy strings in modern C?
Answer: B
strncpy with buffer size check and explicit null termination is the standard safe approach. Option A lacks bounds checking; C and D have issues with null termination.
Q.79Hard
In the declaration int *arr[10], what is arr?
Answer: A
int *arr[10] declares an array of 10 pointers to int (subscript binds tighter than dereference). Use int (*arr)[10] for pointer to array.
Q.80Hard
In a dynamic 2D array created as: int arr = (int)malloc(rows * sizeof(int*)); What is the next step?
Answer: B
After allocating the array of pointers, each row must be allocated separately.