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.
Consider the function declaration: void func(int x); and later in the code: int result = func(5);. What will be the compilation result?
Answer: A
A void function cannot return a value. Attempting to assign the return value of a void function to a variable will cause a compilation error in standard C compilers.
Q.382Hard
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.383Easy
What is the correct way to declare a 1D array of 10 integers in C?
Answer: A
In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.
Q.384Easy
What will be the output of strlen("Hello") in C?
Answer: B
strlen() returns the length of the string excluding the null terminator '\0'. "Hello" has 5 characters.
Q.385Easy
Which of the following is NOT a valid string initialization?
Answer: C
Array names are constant pointers and cannot be reassigned. Direct assignment to char array after declaration is invalid.
Q.386Easy
What does the following code do? strcpy(dest, src);
Answer: B
strcpy() copies the contents of the source string to the destination string.
Q.387Easy
Consider a 2D array declared as: int matrix[3][4]. How many elements does it have?
Answer: D
A 2D array with dimensions 3x4 has 3*4 = 12 total elements.
Q.388Medium
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.389Medium
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.390Medium
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.391Medium
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.392Medium
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.393Medium
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.394Medium
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.395Medium
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.396Medium
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]);