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.
Which function is used to allocate memory dynamically at runtime?
Aalloc()
Bmalloc()
Cmemalloc()
Dallocate()
Correct Answer:
B. malloc()
Explanation:
malloc() is the standard C library function for dynamic memory allocation. It returns a void pointer to the allocated memory block, which can be cast to the required data type.
What is the purpose of the break statement in a switch case?
ATo exit the program
BTo exit the current loop or switch
CTo skip the next statement
DTo pause execution
Correct Answer:
B. To exit the current loop or switch
Explanation:
The break statement terminates the current loop or switch block and transfers control to the statement following the loop or switch. Without it, execution continues to the next case (fall-through).
Which of the following is NOT a valid way to pass arguments to a function in C?
APass by value
BPass by reference
CPass by pointer
DAll are valid
Correct Answer:
B. Pass by reference
Explanation:
C supports pass by value and pass by pointer/address. 'Pass by reference' as a concept exists in C++, not in C. In C, to achieve reference-like behavior, we use pointers.