C questions in placement tests and university exams are rarely about syntax alone. Most of what you will find here is output prediction, pointer arithmetic, arrays and strings, structures and unions, storage classes, recursion, and file handling. The explanations walk through memory behaviour step by step, which is usually where the confusion sits rather than in the code itself.
What will be the output of this code? int counter = 0; void increment() { static int count = 0; count++; counter++; } main() { increment(); increment(); printf("%d %d", count, counter); }
Answer: C
The static variable 'count' is local to increment() and inaccessible from main(). Trying to print 'count' causes compilation error: undefined identifier.
Q.182Medium
Which of the following correctly demonstrates function recursion termination?
Answer: B
A base case is essential in recursive functions to provide a stopping condition. Without it, the function will cause stack overflow. The base case ensures recursion terminates properly.
Q.183Medium
What does the const qualifier do when applied to function parameters?
Answer: A
When const is applied to a function parameter, it prevents modification of that parameter within the function body, making it immutable for the duration of the function.
Q.184Medium
Which statement about extern functions is correct?
Answer: B
extern functions have external linkage and can be accessed from other translation units. It's the default linkage for functions declared outside a file.
Q.185Medium
What is the primary purpose of function pointers in C?
Answer: B
Function pointers enable polymorphism by allowing runtime selection of which function to call. They are crucial for implementing callbacks and dynamic function dispatch.
Q.186Medium
Which of the following is a valid way to return multiple values from a function in C?
Answer: D
C provides multiple methods to return values: structs for encapsulation, pointers for indirect modification, and global variables (though not recommended). All three are technically valid approaches.
Q.187Medium
What happens if a function is declared but never defined in C?
Answer: B
If a function is declared but not defined, the compiler generates code to call it (compilation succeeds), but the linker fails to find the function definition, resulting in a linker error.
Q.188Medium
Consider a function that modifies an array passed as a parameter. Which statement is true?
Answer: B
When an array is passed to a function, it decays to a pointer to its first element. This means modifications to array elements affect the original array outside the function.
Q.189Medium
What is the purpose of function inlining in modern C compilers?
Answer: B
Inlining substitutes a function call with the actual function body at compile time, eliminating function call overhead. This is a compiler optimization for performance-critical code.
Q.190Medium
Which of the following demonstrates proper use of the return statement in error handling?
Answer: D
All three approaches are valid for error handling in C. Functions typically return NULL for pointers, negative values for integers, or use predefined error codes to indicate failure states.
Q.191Medium
A function in C is declared as: int calculate(int *arr, int size). When this function modifies the array elements, what happens to the original array passed from the calling function?
Answer: A
In C, arrays decay to pointers when passed to functions, meaning the address is passed. Any modifications through the pointer affect the original array. This is effectively pass-by-reference behavior for arrays.
Q.192Medium
What will be the output of the following code? char str[] = "Code"; printf("%c", str[2]);
Answer: C
String "Code" has indices: C(0), o(1), d(2), e(3). str[2] refers to 'd'.
Q.193Medium
What is the difference between char str[] = "Test" and char *str = "Test"?
Answer: B
char[] creates a modifiable array with its own storage. char* points to read-only string literal in memory.
Q.194Medium
Which function is used to reverse a string in C library?
Answer: C
There is no standard library function for string reversal. strrev() is non-standard (available in some compilers). Manual reversal or custom functions are needed.
Q.195Medium
What is the output of the following code? int arr[] = {10, 20, 30}; printf("%d", sizeof(arr)/sizeof(arr[0]));
Answer: C
sizeof(arr) gives total bytes of array. sizeof(arr[0]) gives bytes of one element. Division gives number of elements: 3.
Q.196Medium
What will be printed by: printf("%s", "Hello\0World");?
Answer: B
\0 is the null terminator which marks the end of a string. %s stops printing at the first null character.
Q.197Medium
Consider: int *ptr = arr; where arr is an array. What does ptr[2] represent?
Answer: B
ptr[2] is equivalent to *(ptr+2), which points to the third element (index 2) of the array.
Q.198Medium
What will the following code output? char str[20]; strcpy(str, "Competitive"); strcat(str, " Exam"); printf("%s", str);
Answer: C
strcpy copies "Competitive" to str. strcat appends " Exam" to it, resulting in "Competitive Exam".
Q.199Medium
What is the time complexity of searching for an element in an unsorted array of size n?
Answer: C
Linear search on unsorted array requires checking each element in worst case, giving O(n) time complexity.
Q.200Medium
What will be the output of this code? int arr[5]; for(int i=0; i<5; i++) arr[i] = i*i; printf("%d %d %d", arr[1], arr[2], arr[4]);