What will be the output of: int x = 5; printf("%d", ++x);?
Answer: B
The pre-increment operator (++x) increments x from 5 to 6 before using its value in printf(). So the output is 6.
Q.42Hard
Consider a pointer ptr pointing to an integer array. What does ptr[2] represent?
Answer: B
ptr[2] is equivalent to *(ptr+2), which dereferences the pointer and returns the value at the third element (index 2).
Q.43Hard
What is the time complexity of searching for an element in an unsorted array using linear search?
Answer: C
Linear search checks each element sequentially. In the worst case, it needs to check all n elements, resulting in O(n) time complexity.
Q.44Hard
What will be the result of executing: int a = 5, b = 10; int *ptr = &a; ptr = &b; printf("%d", *ptr);?
Answer: B
ptr is reassigned to point to b. When we dereference ptr using *ptr, we get the value stored at b, which is 10.
Q.45Hard
Which of the following statements about static variables is TRUE?
Answer: B
Static variables are initialized only once and retain their value throughout the program execution. Their value persists between function calls.
Advertisement
Q.46Easy
What is the size of an integer variable in most modern C compilers?
Answer: B
On most modern 32-bit and 64-bit systems, an int is typically 4 bytes (32 bits). However, the exact size can vary depending on the compiler and system architecture.
Q.47Easy
Which of the following is NOT a valid C data type?
Answer: B
C does not have a built-in boolean data type. The other options (float, double, char) are all valid primitive data types in C. Boolean functionality is typically implemented using int (0 for false, non-zero for true).
Q.48Easy
What is the purpose of the & operator in C?
Answer: C
The & operator has two uses in C: (1) When used before a variable, it returns the memory address of that variable (address-of operator), and (2) When used between two integers, it performs a bitwise AND operation.
Q.49Easy
Which keyword is used to create a constant variable in C?
Answer: C
The const keyword is used in C to declare a constant variable whose value cannot be modified after initialization. Variables declared as const are read-only.
Q.50Medium
What will be the memory size of the following struct?
struct Point { int x; char c; int y; }
Answer: C
Due to memory alignment/padding: int x (4 bytes), char c (1 byte) + 3 bytes padding, int y (4 bytes) = 12 bytes total. The compiler adds padding to align data members to their natural boundaries for efficient memory access.
Q.51Medium
What is the correct way to initialize an array of 5 integers with all elements as 0?
Answer: C
Both {} and {0} will initialize all array elements to 0. When you provide fewer initializers than array size, remaining elements are automatically set to 0.
Q.52Medium
Which of the following correctly declares a pointer to a pointer?
Answer: B
A pointer to a pointer is declared using two asterisks (). int ptr declares a pointer that points to another pointer that points to an integer.
Q.53Easy
What is the output of sizeof(char) in C?
Answer: B
By the C standard, sizeof(char) is always 1 byte. A char is the smallest addressable unit in C and is defined to be 1 byte.
Q.54Medium
What is the scope of a variable declared inside a function in C?
Answer: B
Variables declared inside a function have local scope (also called function scope). They are only accessible within that function and are destroyed when the function returns.
Q.55Easy
How many times will the loop execute?
for(int i = 0; i < 5; i++)
Answer: B
The loop initializes i to 0 and continues while i < 5. Values of i: 0, 1, 2, 3, 4. After i becomes 5, the condition is false, so the loop executes 5 times.
Q.56Medium
What is the difference between calloc() and malloc() in C?
Answer: D
calloc() allocates memory and initializes all bytes to 0, takes (number of elements, size of each element). malloc() just allocates memory without initialization and takes total size. calloc() is slightly slower due to initialization.
Q.57Easy
What will be the value of x after: int x = 5; x += 3;
Answer: C
The += operator is a compound assignment operator. x += 3 is equivalent to x = x + 3. Therefore, 5 + 3 = 8.
Q.58Medium
What is the correct syntax to open a file in C?
Answer: A
The correct syntax is FILE *fp = fopen("filename", "mode");. fopen() returns a pointer to a FILE structure, and the mode string specifies how to open the file ("r" for read, "w" for write, etc.).
Q.59Medium
Consider the following code:
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
What is the value of *(ptr + 2)?
Answer: C
ptr points to arr[0]. ptr + 2 points to arr[2]. *(ptr + 2) dereferences to get the value at arr[2], which is 3. Pointer arithmetic moves by the size of the data type (integers).
Q.60Medium
What is the output of the following code?
for(int i = 1; i <= 3; i++) { if(i == 2) continue; printf("%d ", i); }
Answer: B
When i = 1, it prints 1. When i = 2, continue skips the printf() and moves to the next iteration. When i = 3, it prints 3. Output: 1 3