C++ Multiple Choice Questions focuses on “Modularization and Interfaces”. One shall practice these questions to improve their C++ programming skills needed for various interviews, entrance exams and other competitive exams.
C++ Questions & Answers focuses on “Modularization and Interfaces” along with answers, explanations and/or solutions:
Q 1. which of the following is used to implement the c++ interfaces?
A. absolute variables
B. abstract classes
C. constant variables
D. default variables
Show Answer
Answer:-B. abstract classesExplanation
Abstract classes in C++ are purposely defined for making base classes containing atleast one virtual function which can be overloaded on inheritance, which means single function name for different sub-classes, hence acts as an interface.Q 2. What is the ability to group some lines of code that can be included?
in the program?
A. specific task
B. program control
C. modularization
D. macros
Show Answer
Answer:-C. modularizationExplanation
Modularization is also similar to macros but it is used to build large projects.Q 3. How many types do functions fall depends on modularization?
A. 1
B. 2
C. 3
D. 4
Show Answer
Answer:-B. 2Explanation
There are two types of functions. They are program control and specific task.Q 4. How many types of modularization are there in c++?
A. 1
B. 2
C. 11
D. 12
Show Answer
Answer:-B. 2Explanation
There are two types of modular programming. They are interface and implementation.Q 5. What does the client module import?
A. macro
B. records
C. interface
D. instance
Show Answer
Answer:-C. interfaceExplanation
Because they access the functions in the module user interface.Q 6. Identify the correct statement.
A. c++ does have built-in interfaces
B. c++ does not have built-in interfaces
C. c++ have no concept of interfaces
D. c++ does have built-in interfaces & classes
Show Answer
Answer:-B. c++ does not have built-in interfacesExplanation
Unlike other programming languages like Java and others, C++ has no inbuilt interfaces.Q 7. What is similar to the interface in c++?
A. methods
B. pure abstract class
C. instance of a class
D. methods & instance of a class
Show Answer
Answer:-B. pure abstract classExplanation
Pure abstract classes in C++ are a type of interface because it contains only abstract member functions and no data or concrete member functions.Q 8. Which of the following implements the module in the program?
A. header files
B. macro
C. macro & header files
D. interfaces
Show Answer
Answer:-A. header filesExplanation
We can include the group of code by using the #include header file.Modularization and Interfaces MCQ
Q 1. Which of the following is the primary purpose of modularization in C++?
A. To make the code run faster
B. To reduce the size of the executable
C. To divide a program into smaller, manageable, and reusable pieces
D. To prevent the use of pointers
Show Answer
Answer:-C. To divide a program into smaller, manageable, and reusable piecesQ 2. Which file extension is typically used for C++ interface (declaration) files?
A. .cpp
B. .exe
C. .h or .hpp
D. .obj
Show Answer
Answer:-C. .h or .hppQ 3. What is the purpose of “Include Guards” (#ifndef, #define, #endif) in header files?
A. To speed up the compilation process
B. To prevent a header file from being included multiple times in the same translation unit
C . To protect the code from being read by others
D. To define global variables
Show Answer
Answer:-B. To prevent a header file from being included multiple times in the same translation unitQ 4. Which keyword is used to create a “pure” interface in C++ (a class that cannot be instantiated and contains only pure virtual functions)?
A. interface
B. abstract
C. virtual (used with = 0)
D. module
Show Answer
Answer:-C. virtual (used with = 0)Q 5. What does the extern keyword signify when used before a variable declaration?
A. The variable is local to the function
B. The variable is defined in another file/translation unit
C. The variable cannot be modified
D. The variable is stored in the CPU registers
Show Answer
Answer:-B. The variable is defined in another file/translation unitQ 6. Which mechanism is used to avoid naming conflicts when combining different modules?
A. Templates
B. Classes
C. Namespaces
D. Inheritance
Show Answer
Answer:-C. NamespacesQ 7. In the context of modularity, what is “Information Hiding”?
A. Encrypting the source code
B. Hiding the implementation details and exposing only the necessary interface
C. Deleting comments before shipping
D. Using private inheritance only
Show Answer
Answer:-B. Hiding the implementation details and exposing only the necessary interfaceQ 8. What is a “Translation Unit” in C++?
A. The final .exe file
B. A single .cpp file plus all the headers included in it
C. The linker’s output
D. A function that translates code to machine language
Show Answer
Answer:-B. A single .cpp file plus all the headers included in itQ 9. Which of the following is true about static functions defined at the file level (outside a class)?
A. They can be accessed from any file in the project
B. They are restricted to the file in which they are defined (internal linkage)
C. They must be virtual
D. They cannot return a value
Show Answer
Answer:-B. They are restricted to the file in which they are defined (internal linkage)Q 10. What happens if a function is declared in a header but never defined in any .cpp file?
A. The compiler will throw an error
B. The program will run but crash
C. The linker will throw an “undefined reference” error
D. The preprocessor will ignore it
Show Answer
Answer:-C. The linker will throw an “undefined reference” errorQ 11. Which C++20 feature was introduced to replace or supplement the traditional header file system?
A. Concepts
B. Coroutines
C. Modules (import, export)
D. Ranges
Show Answer
Answer:-C. Modules (import, export)Q 12. What is the main advantage of C++20 Modules over #include?
A. Modules are compiled only once, reducing build times
B. Modules allow for multiple inheritance
C. Modules make pointers obsolete
D. Modules automatically debug the code
Show Answer
Answer:-A. Modules are compiled only once, reducing build timesQ 13. A class that contains at least one pure virtual function is known as:
A. A Concrete class
B. An Abstract class
C. A Static class
D. A Template class
Show Answer
Answer:-B. An Abstract classQ 14. What is the correct syntax for a pure virtual function?
A. virtual void func() {}
B. void virtual func() = 0;
C. virtual void func() = 0;
D. pure virtual void func();
Show Answer
Answer:-C. virtual void func() = 0;Q 15. In a modular design, “Coupling” refers to:
A. The internal strength of a module
B. The degree of interdependence between modules
C. The number of lines of code in a module
D. The speed of the module
Show Answer
Answer:-B. The degree of interdependence between modulesQ 16. For high-quality modularity, we generally aim for:
A. High Coupling and Low Cohesion
B. Low Coupling and Low Cohesion
C. High Coupling and High Cohesion
D. Low Coupling and High Cohesion
Show Answer
Answer:-D. Low Coupling and High CohesionQ 17. What is the role of the Linker in modular C++ programming?
A. It converts C++ code into assembly
B. It combines multiple object files into a single executable
C. It checks for syntax errors in header files
D. It manages memory allocation at runtime
Show Answer
Answer:-B. It combines multiple object files into a single executableQ 18. Which header is used to define an interface that allows for input/output operations?
A. <iostream>
B. <iomanip>
C. <stdlib.h>
D <string>
Show Answer
Answer:-A.Q 19. Can a C++ interface (abstract class) have a constructor?
A. No, because it cannot be instantiated
B. Yes, to initialize data members that derived classes will use
C. Only if all its functions are private
D. Only if it is a struct
Show Answer
Answer:-B. Yes, to initialize data members that derived classes will useQ 20. When using #include "filename.h", where does the preprocessor look first?
A. The standard system library directory
B. The same directory as the source file
C. The root C:\ drive
D. The compiler’s installation folder


Leave a Reply