Friday, April 4, 2014

couch mode print story

C++ Interview Questions and Answers

C++ Interview Questions and Answers

1. What is C++ ?

C++ is created by Bjarne Stroustrup of AT&T Bell Labs as an extension of C, C++ is an objectoriented
computer language used in the development of enterprise and commercial applications.
Microsoft’s Visual C++ became the premier language of choice among developers and programmers.

2. What are the basic concepts of object oriented programming?

It is necessary to understand some of the concepts used extensively in object oriented programming.These include
1. Objects
2. Classes
3. Data abstraction and encapsulation
4. Inheritance
5. Polymorphism
6. Dynamic Binding
7. Message passing


3. Define polymorphism?

Polymorphism means one name, multiple forms. It allows us to have more than one function with the same
name in a program. It allows us to have overloading of operators so that an operation can exhibit different
behaviors in different instances.


4. Define inheritance?

The mechanism of deriving a new class (derived) from an old class (base class) is called inheritance. It allows
the extension and reuse of existing code without having to rewrite the code from scratch. Inheritance is the
process by which objects of one class acquire properties of objects of another class.


5. What is encapsulation?

The wrapping up of data and functions into a single unit (called class) is known as encapsulation. Encapsulation containing and hiding information about an object, such as internal data structures and code.


6. Define Constructors?

A constructor is a member function with the same name as its class. The constructor is invoked whenever an
object of its associated class is created.It is called constructor because it constructs the values of data
members of the class.


7. What is copy constructor ?

Constructor which initializes it's object member variables with another object of the same class. If you don't
implement one in your class then compiler implements one automatically.


8. What is the use of default constructor?

A constructors that accepts no parameters is called the default constructor.If no user-defined constructor
exists for a class A and one is needed, the compiler implicitly declares a default parameterless constructor
A::A(). This constructor is an inline public member of its class. The compiler will implicitly define A::A() when
the compiler uses this constructor to create an object of type A. The constructor will have no constructor
initializer and a null body.


9. What is destructor ?

A destructor is called for a class object when that object passes out of scope or is explicitly deleted.A
destructors as the name implies is used to destroy the objects that have been created by a constructors. Like a constructor , the destructor is a member function whose name is the same as the class name but is preceded by a tilde.


10. What is virtual destructor ?

A destructor can be virtual as it is possible as at runtime depending on the type of object caller is calling to,
proper destructor will be called.


11. What are tokens in C++?

The smallest individual units of a program is known as tokens. c++ has the following tokens :
 Keywords
 Identifiers
 Constants
 Strings
 Operators


12. What is the use of enumerated data type ?

An enumerated data type is another user defined type which provides a way for attaching names to numbers
thereby increasing comprehensibility of the code. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2, and so on.


13. How variable declaration in c++ differs that in c?

C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables
anywhere in the scope. This makes the programmer easier to understand because the variables are declared
in the context of their use.


14. How can we handle a constructor that fails?

Throw an exception. Constructors don't have a return type, so it's not possible to use return codes. The best
way to signal constructor failure is therefore to throw an exception.


15. What is the difference between Object and Instance?

An instance of a user-defined type is called an object. We can instantiate many objects from one class.
An object is an instance of a class.


16. What is multiple inheritance?

A class can inherit properties from more than one class which is known as multiple inheritance.


17. What is the difference between class and structure?

 By default, the members ot structures are public while that tor class is private.
 structures doesn’t provide something like data hiding which is provided by the classes.
 structures contains only data while class bind both data and member functions.


18. What is dynamic binding?

Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run time.It is associated with polymorphism and inheritance


19. what is difference between function overloading and operator overloading?

A function is overloaded when same name is given to different function. While overloading a function, the return type of the functions need to be the same.


20. What is the difference between a template class and class template?

Template classA generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates.
Class templateA class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes.

Written




0 comments:

Post a Comment