• +91 9723535972
  • info@interviewmaterial.com

CPlusPlus Interview Questions and Answers

CPlusPlus Interview Questions and Answers

Question - 71 : - Explain the ISA and HASA class relationships. How would you implement each in a class design?

Answer - 71 : - A specialized class "is" a specialization of another class and, therefore, has the ISA relationship with the other class. An Employee ISA Person. This relationship is best implemented with inheritance. Employee is derived from Person. A class may have an instance of another class. For example, an employee "has" a salary, therefore the Employee class has the HASA relationship with the Salary class. This relationship is best implemented by embedding an object of the Salary class in the Employee class.

Question - 72 : - When is a template a better solution than a base class?

Answer - 72 : - When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the generosity) to the designer of the container or manager class.

Question - 73 : - How do I initialize a pointer to a function?

Answer - 73 : - This is the way to initialize a pointer to a function void fun(int a) { } void main() { void (*fp)(int); fp=fun; fp(1); }

Question - 74 : - What’s the auto keyword good for?

Answer - 74 : - 1.  Not much. It declares an object with automatic storage duration. Which means the object will be destroyed at the end of the objects scope. All variables in functions that are not declared as static and not dynamically allocated have automatic storage duration by default. For example int main() { int a; //this is the same as writing “auto int a;” } 2. Local variables occur within a scope; they are “local” to a function. They are often called automatic variables because they automatically come into being when the scope is entered and automatically go away when the scope closes. The keyword auto makes this explicit, but local variables default to auto auto auto auto so it is never necessary to declare something as an auto auto auto auto.

Question - 75 : - What is a mutable member?

Answer - 75 : - One that can be modified by the class even when the object of the class or the member function doing the modification is const.

Question - 76 : - What is an explicit constructor?

Answer - 76 : - A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It’s purpose is reserved explicitly for construction.

Question - 77 : - What is the Standard Template Library (STL)?

Answer - 77 : - A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.

Question - 78 : - Describe run-time type identification.

Answer - 78 : - The ability to determine at run time the type of an object by using the typeid operator or the dynamic_cast operator.

Question - 79 : - What problem does the namespace feature solve?

Answer - 79 : - Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library’s external declarations with a unique namespace that eliminates the potential for those collisions. This solution assumes that two library vendors don’t use the same namespace identifier, of course.

Question - 80 : - Are there any new intrinsic (built-in) data types?

Answer - 80 : - Yes. The ANSI committee added the bool intrinsic type and its true and false value keywords.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners