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.142Medium
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.143Hard
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.144Easy
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.145Medium
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.
Advertisement
Q.146Medium
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.147Medium
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.148Easy
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.149Easy
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.150Medium
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.151Medium
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.
Q.152Easy
What will be the value of x after executing: int x = 5; x += 3; x *= 2;
Answer: B
Step 1: x = 5. Step 2: x += 3 means x = x + 3 = 5 + 3 = 8. Step 3: x *= 2 means x = x * 2 = 8 * 2 = 16. Therefore, x = 16.
Q.153Hard
Which of the following correctly describes the relationship between arrays and pointers in C?
Answer: B
In C, when an array name is used in most contexts, it decays (converts) to a pointer to its first element. For example, in int arr[5];, arr behaves like &arr[0]. However, arrays and pointers are not identical; arrays have fixed size while pointers are variables.
Q.154Medium
What is the output of the expression: 310 * 3 in C?
Answer: B
Division and multiplication have the same precedence and are evaluated left-to-right. Step 1: 310 = 3 (integer division). Step 2: 3 * 3 = 9. Therefore, the result is 9.
Q.155Easy
Which preprocessor directive is used to include a custom header file?
Answer: B
Custom/local header files are included using double quotes: #include "filename". Standard library headers use angle brackets: #include <filename>. The compiler searches for quoted files in the current directory first.
Q.156Hard
What is the difference between a function declaration and a function definition in C?
Answer: A
A function declaration (or prototype) tells the compiler about the function's name, return type, and parameters. A function definition includes the declaration along with the function body containing the actual implementation. Declaration is optional if the function is defined before use.
Q.157Hard
Which of the following is the correct way to declare a pointer to a function that returns an int and takes two int parameters?
Answer: B
The correct syntax for a function pointer is: int (*ptr)(int, int);. The parentheses around (*ptr) are necessary to indicate that ptr is a pointer to a function, not a function returning a pointer. Option A declares a function returning an int pointer.
Q.158Easy
Which of the following is NOT a valid variable name in C?
Answer: C
Variable names in C cannot start with a digit. They must begin with a letter (a-z, A-Z) or underscore (_). '123myVar' is invalid.
Q.159Easy
What will be the output of: printf("%d", 5 + 3 * 2);?
Answer: B
Operator precedence: multiplication (*) is performed before addition (+). So: 3 * 2 = 6, then 5 + 6 = 11.
Q.160Easy
What keyword is used to create a pointer variable in C?
Answer: B
The asterisk (*) symbol is used to declare pointer variables. For example: int *ptr; declares a pointer to an integer.