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 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.2Easy
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.3Easy
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.4Easy
What does the following code do? strcpy(dest, src);
Answer: B
strcpy() copies the contents of the source string to the destination string.
Q.5Easy
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.6Medium
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.7Medium
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.8Medium
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.9Medium
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.10Medium
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.11Medium
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.12Medium
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.13Medium
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.14Medium
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]);