What is the correct way to declare a pointer to an integer?
Answer: B
The correct syntax is 'int *p;' where int is the data type, * indicates pointer, and p is the pointer variable name.
Q.182Medium
What is the output of: int x = 5; int y = ++x; ?
Answer: B
The pre-increment operator ++x increments x first (from 5 to 6), then assigns the new value to y. So x = 6 and y = 6.
Q.183Medium
What is the purpose of the free() function in C?
Answer: B
The free() function deallocates (releases) memory that was previously allocated using malloc(), calloc(), or realloc().
Q.184Medium
Which of the following correctly defines a structure in C?
Answer: C
The correct syntax uses the 'struct' keyword followed by the structure name and then the member declarations enclosed in braces.
Q.185Medium
What will be the value of x after executing: int x = 10; x += 5; x *= 2; ?
Answer: B
Step 1: x = 10. Step 2: x += 5 means x = x + 5 = 15. Step 3: x *= 2 means x = x * 2 = 15 * 2 = 30.
Advertisement
Q.186Medium
Which loop construct will execute at least once even if the condition is false?
Answer: C
The do-while loop executes the body first and then checks the condition, ensuring at least one execution. while and for loops check the condition first.
Q.187Medium
How is a two-dimensional array typically stored in memory in C?
Answer: C
C uses row-major order to store 2D arrays in memory. The elements are stored row by row sequentially in memory.
Q.188Hard
What is the difference between #include <stdio.h> and #include "stdio.h"?
Answer: D
Using <> tells the compiler to search in standard system directories. Using "" tells it to search in the current directory first, then system directories. Generally, "" is used for user-defined headers and <> for standard library headers.
Q.189Hard
Consider the code: int *p; int arr[5]; p = arr; What does p[2] represent?
Answer: B
When p points to arr, p[2] is equivalent to *(p+2) and accesses the value at arr[2]. Pointers and array names decay to pointers, and pointer indexing retrieves the value.
Q.190Hard
Which of the following will correctly allocate memory for an array of 10 integers?
Answer: B
malloc() allocates memory in bytes. To allocate for 10 integers, we need 10 * sizeof(int) bytes. Option A allocates only 10 bytes, insufficient for 10 integers.
Q.191Hard
What will be the output of: int x = 5; int y = x++ + ++x; ?
Answer: D
This expression involves modifying the same variable (x) multiple times without an intervening sequence point. This is undefined behavior in C, and the result cannot be predicted reliably.
Q.192Easy
Which function is used to read a single character from standard input?
Answer: B
getchar() reads a single character from standard input (stdin). While fgetc() can also read a character, getchar() is the standard dedicated function for this purpose.
Q.193Easy
In the expression: int arr[3][3]; arr[1][2] = 5; What is being accessed?
Answer: A
In C, array indices are 0-based. arr[1][2] refers to the element in the second row (index 1) and third column (index 2) of the 2D array.
Q.194Easy
What is the output of the following C code?
int main() {
int a = 10;
printf("%d", a += 5);
return 0;
}
Answer: B
The += operator adds 5 to a (a = a + 5 = 10 + 5 = 15), and printf prints the updated value 15.
Q.195Medium
What is the output of the following code?
int x = 5;
int y = ++x;
printf("%d %d", x, y);
Answer: B
++x is pre-increment, which increments x before assignment. So x becomes 6, then y is assigned 6. Both x and y are 6.
Q.196Easy
What is the purpose of the strlen() function in C?
Answer: B
The strlen() function returns the number of characters in a string, excluding the null terminator ('\0').
Q.197Medium
What will be the output of the following code?
int *ptr;
int arr[3] = {10, 20, 30};
ptr = arr;
printf("%d", *(ptr + 1));
Answer: B
ptr points to arr[0] (value 10). ptr + 1 points to arr[1] (value 20). *(ptr + 1) dereferences this pointer, giving 20.
Q.198Hard
What is the output of this recursive function?
int func(int n) {
if(n <= 1) return 1;
return n * func(n-1);
}
printf("%d", func(4));
What is the output of this code involving bitwise operations?
int x = 5; // binary: 0101
int y = 3; // binary: 0011
printf("%d", x ^ y); // XOR operation
Answer: A
XOR operation: 5 ^ 3. Binary: 0101 ^ 0011 = 0110 = 6. XOR returns 1 when bits are different, 0 when same.
Q.200Easy
What will be the value of 'x' after execution of the following code? int x = 10; x += 5; x *= 2;
Answer: B
Step 1: x = 10 initially. Step 2: x += 5 means x = x + 5 = 10 + 5 = 15. Step 3: x *= 2 means x = x * 2 = 15 * 2 = 30. Therefore, x = 30.