Which of the following is a correct way to initialize a 1D array in C?
Aint arr[5] = {1, 2, 3, 4, 5};
Bint arr[] = {1, 2, 3, 4, 5};
Cint arr[5];
DAll of the above
Correct Answer:
D. All of the above
Explanation:
All three methods are valid. Option A initializes with size 5, option B auto-determines size from initialization, and option C declares without initialization.
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
A10
BError
CMAX
DUndefined
Correct Answer:
A. 10
Explanation:
The #define directive replaces MAX with 10 during preprocessing. So x = 10 and output is 10. (Note: semicolon after MAX is not needed but doesn't affect the output)
Which header file is essential for using the printf() function in C?
A#include
B#include
C#include
D#include
Correct Answer:
B. #include
Explanation:
The stdio.h header file contains declarations for standard input/output functions like printf(). Option A is C++, Option C is C++, and Option D is for memory allocation functions.