C++ Interview Questions and Answers for Freshers - 3

Question: 11

When do you call copy constructor?

Copy constructors are called in these situations:

When compiler generates a temporary object

When a function returns an object of that class by value

When the object of that class is passed by value as an argument to a function

When you construct an object based on another object of the same class.

Question: 12

Explain Stack and Heap Objects?

The memory a program uses is divided into four areas:

The code area: this is where the compiled program sites in memory.

The global area: the place where global variables are stored.

The heap: the place where dynamically allocated variables are allocated from.

The stack: the place where parameters and local variables are allocated from.

Question: 13

What is the difference between new() and calloc()?

new () allocates continous space for the object instance malloc() allocates distributed space.

new() is castles, meaning that allocates memory for this specific type, malloc(), calloc() allocates space for void * that is created to the specific class type pointer.

Question: 14

What is an accessor?

An accessor is a class operation that does not modify the state of an object.

The accessor functions need to be declared as const operations.

Question: 15

What is a conversion constructor?

A constructor that accepts one argument of a different type.

Related Questions