cpp exercise1

C++ exercise

1. Which access specifier is used as a default in a class definition ?

a. public
b. private
c. protected
d. friend

Show Answer

The correct option is (b)
Explanation:
Private access specifier is used as a default in a class definition.

2.By Not using virtual destructor feature in a C++ language object oriented programing can cause

a. Memory leak
b. An Issue in creating object of the class
c. An issue in calling base class destructor
d. None of the above

Show Answer

The correct option is (a)
Explanation:
in c++ Virtual destructor is use to maintain the hierarchy of destructor calls for polymorphic classes in inheritance. If we do not use it then it may cause resource leak or memory leak.

3. Which of the following is a mechanism of static polymorphism ?

a.function overloading
b.Templates
c. Operator overloading
d.All of the above

Show Answer

The correct option is (a)
Explanation:
Function overloading is a mechanism of static polymorphism.

4. IS A relationship in C++ is?

a. Encapsulation
b. Inheritance
c. Composition
d. None of the above

Show Answer

The correct option is (b)
Explanation:
Explanation: IS A relationship in C++ is Inheritance.

5. Which of the following is called address operator ?

a. &
b. *
c. _
d. %

Show Answer

The correct option is (a)
Explanation:
& operator is called address operator and is used to access the address of a variable

6. What are the actual parameters in C++ ?

a. Parameters which are used in the definition of a function.
b. Parameters with which functions are called.
c. Variables that are never used in the function
d. Variables other than passed parameters in a function

Show Answer

The correct option is (b)
Explanation:
Actual parameters are those using which a function call is made i.e. which are actually passed in a function when that function is called

7. Which function is used to read a single character from the console in C++ ?

a. getline(ch).
b. cin.get(ch).
c. scanf(ch)
d. read(ch)

Show Answer

The correct option is (b)
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.

8. Which function is used to write a single character to console in C++ language ?

a. cout.putline(ch)
b. cout.put(ch)
c. write(ch)
d. printf(ch)

Show Answer

The correct option is (b)
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

8. What are the escape sequences ?

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

Show Answer

The correct option is (c)
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.

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise