C++ program to swap two numbers using pointers and references

C++ program to swap two numbers using pointers and references and functions. Swapping two number using pointers concept is applicable to both C and C++. But, swapping two numbers by reference is applicable to C++ only, as C language does not support references. Recommended Read more →

What is difference between pointer and reference in C++

Before listing the difference between pointer and reference in C++ , lets see the definition of pointer and reference. Pointer: A pointer is a simply variable that stores the address of another variable. The variable can also be another pointer. Reference: A reference is Read more →

In what situations initialization list is must and assignment in constructor body does not help?

Answer: Here is the some of the scenarios where we must use initialization list in C++. Scenario-1: initialization of constant & reference data member of a class. In C++, constant or reference data member variables of a class can only be initialized in the Read more →

What is order of calling constructor and destructor in C++?

Order of execution of constructors and destructors in C++ is frequently asked interview question. For this question, we have to answer c++ constructor call order and destructor call order  in inheritance relationship with a program example.   [NOTE: During answering c++ inheritance destructor order question, Read more →

what is order of constructor call for composed objects in a class?

Answer: Order of constructor call for composed objects in a class would be as below. Consider an example of Mobile class, composed of Battery and Sim class. Constructor call of composed objects  will be as in order they have declared. Then constructor of main Read more →

Can Copy constructor accept object by value instead of reference?

Answer: No, in C++, a copy constructor doesn’t support pass by value but pass by reference only. It cannot accept object parameter by value and it should always receive it as a reference. An error, “Illegal copy constructor” will be thrown if we receive Read more →

Write simple program to overload new and delete operator in C++

Answer includes a simple program to overload new and delete operator in C++ class with important points about overloaded new and delete. Below is the C++ code example program for overloading new and delete operator. C++ syntax for overloading new and delete is simple. Read more →