© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

4. Explain the scope resolution operator?

Ans:

It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

Ex Q1: How many ways are there to initialize an int with a constant?

Ans:

1. int foo = 123;
2. int bar(123);

Ex Q2: What is the difference between a copy constructor and an overloaded assignment operator?

Ans:

A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.

Ex Q3: When should you use multiple inheritance?

Ans:

There are three acceptable answers:- "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way." Consider an Asset class, Building class, Vehicle class, and CompanyCar class. All company cars are vehicles. Some company cars are assets because the organizations own them. Others might be leased. Not all assets are vehicles. Money accounts are assets. Real estate holdings are assets. Some real estate holdings are buildings. Not all buildings are assets. Ad infinitum. When you diagram these relationships, it becomes apparent that multiple inheritance is a likely and intuitive way to model this common problem domain. The applicant should understand, however, that multiple inheritance, like a chainsaw, is a useful tool that has its perils, needs respect, and is best avoided except when nothing else will do.

Ex Q4: Can a constructor throw a exception? How to handle the error when the constructor fails?

Ans:

The constructor never throws a error.

Ex Q5: What is a node class?

Ans:

A node class is a class that,
Ø  relies on the base class for services and implementation,
Ø  provides a wider interface to te users than its base class,
Ø  relies primarily on virtual functions in its public interface
Ø  depends on all its direct and indirect base class
Ø  can be understood only in the context of the base class
Ø  can be used as base for further derivation
Ø  can be used to create objects.
A node class is a class that has added new services or functionality beyond the services inherited from its base class.   

SLogix Student Projects
bottom