What is the output of the following code: printf("%d", sizeof(int));
A2 bytes
B4 bytes
CThe code will print a number (typically 4 on most systems)
DError in compilation
Correct Answer:
C. The code will print a number (typically 4 on most systems)
Explanation:
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.
Which of the following correctly initializes a 2D array in C?
Aint arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
Bint arr[][3] = {1,2,3,4,5,6,7,8,9};
CBoth A and B are correct
DNeither A nor B is correct
Correct Answer:
C. Both A and B are correct
Explanation:
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.
Which of the following is NOT a valid identifier in C?
A_variable123
B123_variable
Cvariable_123
DVariable_123
Correct Answer:
B. 123_variable
Explanation:
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.
In C, what is the difference between single quotes and double quotes?
ANo difference, they are interchangeable
BSingle quotes are for characters, double quotes are for strings
CSingle quotes for strings, double quotes for characters
DSingle quotes cannot be used in C
Correct Answer:
B. Single quotes are for characters, double quotes are for strings
Explanation:
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).
Which of the following is true about the 'break' statement in C?
AIt skips the current iteration
BIt exits the loop or switch statement
CIt terminates the program
DIt has no effect in loops
Correct Answer:
B. It exits the loop or switch statement
Explanation:
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.
What will be the memory size occupied by: int arr[5][3];?
A15 bytes
B60 bytes
C30 bytes
DDepends on the compiler
Correct Answer:
B. 60 bytes
Explanation:
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).
Which loop construct in C guarantees execution at least once?
Awhile loop
Bfor loop
Cdo-while loop
Dnested loop
Correct Answer:
C. do-while loop
Explanation:
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.
What is the scope of a variable declared inside a block?
AGlobal scope
BLocal scope (block scope)
CStatic scope
DExternal scope
Correct Answer:
B. Local scope (block scope)
Explanation:
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.