C++ Questions and Answers Part-2

1. Which concept allows you to reuse the written code?
a) Encapsulation
b) Polymorphism
c) Inheritance
d) Abstraction

Answer: c
Explanation: Inheritance allows you to reuse your already written code by inheriting the properties of written code into other parts of the code, hence allowing you to reuse the already written code.

2. C++ is ______________
a) functional programming language
b) procedural programming language
c) object oriented programming language
d) both procedural and object oriented programming language

Answer: d
Explanation: C++ supports both procedural (step by step instruction) and object oriented programming (using concept of classes and objects).

3. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include <userdefined>
b) #include <userdefined.h>
c) #include “userdefined”
d) #include [userdefined]

Answer: c
Explanation: C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.

4. What are the escape sequences?
a) Set of characters that convey special meaning in a program
b) Set of characters that whose use are avoided in C++ programs
c) Set of characters that are avoided in cout statements
d) Set of characters that are used in the name of the main function of the program

Answer: a
Explanation: Escape sequence is a set of characters that convey a special meaning to the program. They are used to convey a meaning which cannot be conveyed directly.

5. Which of the following escape sequence represents tab?
a) \t\r
b) \a
c) \t
d) \b

Answer: c
Explanation: \t is used to represent tab which means a set of blank spaces in a line.

6. Wrapping data and its related functionality into a single entity is known as _____________
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Modularity

Answer: b
Explanation: In OOPs, the property of enclosing data and its related functions into a single entity(in C++ we call them classes) is called encapsulation.

7. What does modularity mean?
a) Overriding parts of program
b) Hiding part of program
c) Wrapping things into single unit
d) Subdividing program into small independent parts

Answer: d
Explanation: Modularity means dividing a program into independent sub programs so that it can be invoked from other parts of the same program or any other program.

8. Which function is used to read a single character from the console in C++?
a) cin.get(ch)
b) read(ch)
c) getline(ch)
d) scanf(ch)

Answer: a
Explanation: C++ provides cin.get() function to read a single character from console whereas others are used to read either a single or multiple characters.

9. What does polymorphism in OOPs mean?
a) Concept of allowing overiding of functions
b) Concept of hiding data
c) Concept of wrapping things into a single unit
d) Concept of keeping things in differnt modules/files

Answer: a
Explanation: In OOPs, Polymorphism is the concept of allowing a user to override functions either by changing the types or number of parameters passed.

10. Which function is used to write a single character to console in C++?
a) printf(ch)
b) write(ch)
c) cout.put(ch)
d) cout.putline(ch)

Answer: c
Explanation: C++ provides cout.put() function to write a single character to console whereas others are used to write either a single or multiple characters.