Which of the following correctly initializes a 2D array in C?
Answer: C
Both syntaxes are valid in C. Option A explicitly specifies both dimensions, while Option B lets the compiler calculate the first dimension based on initialization.
Q.42Easy
Which of the following is NOT a valid identifier in C?
Answer: B
In C, an identifier cannot start with a digit. It must start with a letter (a-z, A-Z) or underscore (_). Option B violates this rule by starting with a digit.
Q.43Easy
In C, what is the difference between single quotes and double quotes?
Answer: B
In C, single quotes (') are used for single character constants (char type), while double quotes (") are used for string literals (array of characters ending with null terminator).
Q.44Easy
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.
Q.45Easy
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.
Advertisement
Q.46Easy
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.47Easy
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.48Easy
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.49Easy
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.50Easy
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.51Easy
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.52Easy
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.53Easy
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.
Q.54Easy
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.55Easy
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.56Easy
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.57Easy
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.58Easy
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.59Easy
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.
Q.60Easy
Which header file must be included to use the printf() function in C?
Answer: B
The printf() function is defined in the Standard Input/Output library. Therefore, '#include <stdio.h>' must be included at the beginning of the program to use printf() and other I/O functions like scanf(), getchar(), putchar(), etc.