C++ interview


C++ TechClinch
C++ TechClinch

 

C++ is a programming language that is implemented on a wide variety of operating system platforms and used for hardware design. This language has following features:

Compiled,
Statically typed,
Multi-paradigm and
Free-form.
This Language also consists of both high-level and low-level language features.

Here is a list of C++ Interview questions with answers which are asked at the time of campus interviews, placements and we have attached pdf also.

C++ Interview Questions with Answers:

1. What is C++?
C++ is created by Bjarne Stroustrup of AT&T Bell Labs as an extension of C, C++ is an object-oriented 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. 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.

3. 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.

4. What is the difference between C & C++?

C++ is an object oriented programing but c is a procedure oriented programing. C is super set of C++. C can’t support inheritance, function overloading, method overloading etc. but C++ can do this. In c-program the main function could not return a value but in the C++ the main function should return a value.

5. What do you mean by implicit conversion?

Whenever data types are mixed in an expression then C++ performs the conversion automatically.
Here smaller type is converted to wider type.
Example : in case of integer and float integer is converted into float type.

6. What is the difference between class and structure?

By default, the members of 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.
7. 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.

8. 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.
9. What is friend function?

The function declaration should be preceded by the keyword friend. The function definitions does not use either the keyword or the scope operator ::. The functions that are declared with the keyword friend as friend function. Thus, a friend function is an ordinary function or a member of another class.

10. What is an iterator?

Iterators are like pointers. They are used to access the elements of containers thus providing a link between algorithms and containers. Iterators are defined for specific containers and used as arguments to algorithms.

11. What are the differences between new and malloc?

New initializes the allocated memory by calling the constructor. Memory allocated with new should be released with delete.
Malloc allocates uninitialized memory.
The allocated memory has to be released with free. New automatically calls the constructor while malloc (doesn’t).
12. What is an explicit constructor?

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. Explicit constructors are simply constructors that cannot take part in an implicit conversion.

13. What do you mean by inline function?

An inline function is a function that is expanded inline when invoked.ie. the compiler replaces the function call with the corresponding function code. An inline function is a function that is expanded in line when it is invoked. That is the compiler replaces the function call with the corresponding function code (similar to macro).

14. What is the difference between a copy constructor and an overloaded assignment operator?

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.

15. What is class invariant?

A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.

One thought on “C++ interview

  1. This is really cool. Such vaeirty in the starting arrangements! It really has a huge impact on how one solves the puzzle.I have solved about half so far, keeping notes as I go, and I also noticed some variation in the solving times (so far the longest took about 10x as long as the shortest!).But I assume our votes are not necessarily supposed to imply difficulty or solving time, but a more subjective assessment of how much we enjoyed / admired / had fun with them (independent of whether we solved them quickly or slowly) … right?

Leave a Reply

Your email address will not be published. Required fields are marked *