Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 23
Q401:
What happens if you redefine a macro without undefining it first?
A. No impact
B. Compilation error
C. Program runs slower
D. The macro is updated automatically
Correct Answer:
B
Chapter: 23
Q402:
What is the main advantage of using macros over functions?
A. Easier to write
B. Saves memory
C. Faster execution
D. Easier debugging
Correct Answer:
C
Chapter: 23
Q403:
Why should variable names not start with an underscore?
A. It is reserved for internal use
B. It is not allowed
C. It causes syntax errors
D. It is harder to read
Correct Answer:
A
Chapter: 23
Q404:
What is the purpose of #pragma directive?
A. It is used for debugging
B. It is used to suppress warnings
C. It is used to set compiler-specific instructions
D. It is used to define constants
Correct Answer:
C
Chapter: 23
Q405:
How can you execute a block of code only when a macro is defined?
A. Use #ifdef followed by #endif
B. Use #define followed by #endif
C. Use #undef followed by #ifdef
D. Use #include followed by #pragma
Correct Answer:
A
Chapter: 23
Q406:
What directive is used to include header files in the source code?
A. #define
B. #ifdef
C. #include
D. #undef
Correct Answer:
C
Chapter: 23
Q407:
Which of the following is not a preprocessor directive in C?
A. #pragma
B. #assert
C. #endif
D. #execute
Correct Answer:
D
Chapter: 24
Q408:
What is dynamic memory allocation?
A. Allocation of memory at runtime
B. Allocation of memory at compile time
C. Allocation of memory on stack
D. Allocation of memory in registers
Correct Answer:
A
Chapter: 24
Q409:
Which function is used to allocate memory dynamically in C?
A. malloc()
B. calloc()
C. realloc()
D. All of the above
Correct Answer:
D
Chapter: 24
Q410:
What type of pointer is returned by dynamic memory allocation functions in C?
A. int pointer
B. void pointer
C. char pointer
D. float pointer
Correct Answer:
B
Chapter: 24
Q411:
What does the calloc function do apart from allocating memory?
A. It initializes the memory to zero
B. It initializes the memory to one
C. It doesn't initialize memory
D. It deallocates memory
Correct Answer:
A
Chapter: 24
Q412:
Which header files define the NULL macro in C?
A. stdlib.h and stddef.h
B. string.h and stdio.h
C. malloc.h and memory.h
D. math.h and conio.h
Correct Answer:
A
Chapter: 24
Q413:
What is the purpose of the free() function in dynamic memory allocation?
A. To allocate memory dynamically
B. To deallocate memory and return to heap
C. To initialize memory to zero
D. To copy memory contents
Correct Answer:
B
Chapter: 24
Q414:
How does malloc differ from calloc in memory initialization?
A. malloc initializes memory to zero
B. malloc initializes memory to one
C. malloc does not initialize memory
D. malloc initializes memory to NULL
Correct Answer:
C
Chapter: 24
Q415:
What does realloc do when it cannot extend the current memory block?
A. Allocates a new block and copies contents
B. Returns NULL
C. Keeps the current block unchanged
D. Terminates the program
Correct Answer:
A
Chapter: 24
Q416:
What should be checked after every dynamic memory allocation call?
A. Whether the pointer is NULL
B. Whether the memory is full
C. Whether the stack is empty
D. Whether the memory is contiguous
Correct Answer:
A
Chapter: 24
Q417:
Which operator is used for casting a void pointer to a specific data type in C?
A. sizeof
B. malloc
C. free
D. Standard cast operator
Correct Answer:
D
Chapter: 25
Q418:
Which programming language was primarily used for writing the Unix operating system?
A. COBOL
B. FORTRAN
C. C
D. C++
Correct Answer:
C
Chapter: 25
Q419:
What approach does C follow in structured programming?
A. Bottom-up
B. Top-down
C. Object-Oriented
D. Data-driven
Correct Answer:
B
Chapter: 25
Q420:
What was C++ initially called?
A. C with Classes
B. C plus plus
C. Java
D. Structured C
Correct Answer:
A