Which of the following is a correct way to declare a pointer to an integer in C?
Answer: B
The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates it is a pointer variable.
Q.42Easy
What is the output of the following code: printf("%d", sizeof(int));
Answer: C
sizeof(int) returns the size of integer in bytes as an integer value. On most modern systems, this is 4 bytes, and printf with %d will print this numeric value.
Q.43Easy
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.44Easy
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.45Easy
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).
Advertisement
Q.46Easy
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.47Easy
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.48Easy
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.49Easy
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.50Easy
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.51Easy
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.52Easy
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.53Easy
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.54Easy
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.55Easy
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.56Easy
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.57Easy
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.58Easy
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.59Easy
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.60Easy
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').