Which of the following correctly represents a structure declaration in C?
Answer: C
Both are valid syntax. Option A declares an anonymous structure with immediate variable instantiation. Option B declares a named structure type that can be used later to create variables.
Q.142Hard
What does the 'volatile' keyword indicate in C?
Answer: A
The volatile keyword tells the compiler that a variable's value may change unexpectedly (e.g., due to hardware, interrupts, or other threads), preventing compiler optimizations that assume the value doesn't change.
Q.143Hard
Consider: int *ptr; int arr[] = {1,2,3}; ptr = arr; What is ptr[1]?
Answer: B
When ptr points to the array arr, ptr[1] is equivalent to *(ptr+1), which accesses the second element of the array, which is 2.
Q.144Medium
Which of the following operators has the highest precedence in C?
Answer: B
The increment (++) and decrement (--) operators have the highest precedence among all operators in C, followed by unary operators, then multiplicative, additive, and so on.
Q.145Easy
Which of the following is true about the 'break' statement in C?
Answer: B
The 'break' statement is used to exit or terminate a loop or switch statement immediately. It transfers control to the statement following the loop or switch.
Advertisement
Q.146Medium
What will be printed: int i = 0; while(i < 3) { printf("%d ", i); i++; }
Answer: A
The while loop starts with i=0. It prints 0, then increments i to 1, prints 1, increments to 2, prints 2, increments to 3, and the condition i<3 becomes false, so the loop terminates. Output: 0 1 2
Q.147Medium
What is the correct syntax to free dynamically allocated memory in C?
Answer: B
The free() function is used to deallocate memory that was previously allocated using malloc(), calloc(), or realloc(). This prevents memory leaks.
Q.148Medium
What does the following code do: int *ptr = NULL;
Answer: B
This declaration creates a pointer to an integer and initializes it to NULL, which means it doesn't point to any valid memory address. This is a safe initialization practice.
Q.149Medium
What is the output of: printf("%f", 25);
Answer: B
Since both 5 and 2 are integers, integer division is performed: 25 = 2. The %f format specifier then prints this integer value (2) as a floating-point number: 2.000000
Q.150Easy
Which of the following correctly declares a 2D array in C?
Answer: A
A 2D array in C is declared using the syntax: datatype arrayName[rows][columns]. So 'int arr[3][4];' creates a 2D array with 3 rows and 4 columns.
Q.151Medium
What does the sizeof() operator return in C?
Answer: B
The sizeof() operator returns the size in bytes of a data type or variable. For example, sizeof(int) typically returns 4 on most 32-bit systems.
Q.152Hard
What is the difference between getchar() and scanf("%c", &ch); in C?
Answer: C
getchar() specifically reads a single character from the standard input stream, while scanf("%c", &ch) is a formatted input function. getchar() is more straightforward for reading single characters.
Q.153Easy
What will be the memory size occupied by: int arr[5][3];?
Answer: B
The array has 5 rows and 3 columns, so total elements = 5 × 3 = 15 elements. Each int typically occupies 4 bytes. Total memory = 15 × 4 = 60 bytes (assuming sizeof(int) = 4 bytes on most systems).
Q.154Medium
What does the modulus operator (%) return when applied to negative numbers?
Answer: B
In C, the modulus operator (%) returns a remainder that has the same sign as the dividend. For example, -7 % 3 = -1 (not 2), because -7 is the dividend and it's negative.
Q.155Medium
Which of the following statements about pointers is correct?
Answer: B
A pointer is a variable that stores the memory address of another variable. You can access the value at that address using the dereference operator (*), and pointers can point to any data type.
Q.156Medium
What is the correct way to declare a constant in C?
Answer: D
Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare a constant in C. The const keyword can be placed before or after the type specifier, and both have the same meaning.
Q.157Easy
Which loop construct in C guarantees execution at least once?
Answer: C
The do-while loop executes the body at least once before checking the condition. The syntax is: do { statements; } while(condition);. In contrast, while and for loops check the condition first.
Q.158Easy
What is the scope of a variable declared inside a block?
Answer: B
Variables declared inside a block (enclosed in curly braces) have local or block scope. They are accessible only within that block and cease to exist once the block execution is complete.
Q.159Medium
How many times will the following loop execute: for(int i=0; i<5; i++) { if(i==3) break; }
Answer: B
The loop executes for i=0, i=1, and i=2. When i=3, the break statement is encountered, which immediately terminates the loop. Therefore, the loop executes exactly 3 times.
Q.160Medium
Which of the following is a correct way to initialize a pointer to NULL?
Answer: D
All three methods are correct ways to initialize a pointer to NULL. 0, NULL, and (void*)0 all represent a null pointer. NULL is typically a macro defined as 0 or ((void*)0) in the standard library.