C++ Interview Question and Answers

91. How can a struct in C++ differs from a struct in C?
 
    The differences between struct in C++ and C are listed in the following points:
  • In C and C++, the variables of the structures are public; however, in C, the variable cannot be declared as private or protected. On the contrary, in C++, the variables can be declared as private or protected.
  • In C, the concept of inheritance is not supported. In C++, the concept of inheritance is fully supported.
  • On declaring a struct in C, the addition of the struct keyword is must. On the contrary, there is no need of the struct keyword on declaring struct in C++.
  • In C, the initialization cannot be done outside the scope of a structure. However, in C++, the initialization can be done outside the scope of a structure.
  • In C, structures do not have direct functions or methods.
 
Your Name Your Email-ID
Your Answer
92. How the keyword struct is different from the keyword class in C++?
  In C++, a class is similar to a struct with the exception that, by default, all the members of a class are private; while the members of a struct are public. Encapsulation is not supported by structures but supported by classes.
 
Your Name Your Email-ID
Your Answer
93. Define pure virtual function?
  Pure virtual function is defined as a virtual function in a base class. It is implemented in a derived class. A program may not declare an instance of a class that has a pure virtual function.
 
Your Name Your Email-ID
Your Answer
94. Define a conversion constructor?
  A conversion constructor is a single argument constructor. It is used by the compiler to ocnvert a type of objects as an argument to a class type.
 
Your Name Your Email-ID
Your Answer
95. What is a default constructor?
  A zero argument constructor or a constructor in which all the arguments have default values is called a default constructor.
 
Your Name Your Email-ID
Your Answer