C++ Interview Questions and Answers for Freshers - 2

Question: 6

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.

Question: 7

What is a modifier?

A modifier, also called a modifying function is a member function that changes the value of at least one data member.

In other words, an operation that modifies the state of an object. Modifies are also known as ‘mutators’.

Question: 8

What is function overloading and operator overloading?

Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order to the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.

Operator overloading – allows existing C++ operators to be preferred so that they work on objects of user defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant façade that doesn’t add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

Question: 9

Explain Copy Constructor?

It is a constructor which initializes its object member variable with another object of the same class.

If you don’t implement a copy constructor in your class, the compiler automatically does it.

Question: 10

What is the type of ‘this’ pointer?

It is a constant pointer type. It gets created when a non static member function of a class is called.

Related Questions