Skip to content

Category Archives: C++

We have discussed assignment operator overloading for dynamically allocated resources here. In this article, we discussed that when we don’t write our own assignment operator,… Read More
The answer is same as Copy Constructor. If a class doesn’t contain pointers, then there is no need to write assignment operator and copy constructor.… Read More
Function overloading is a feature of object-oriented programming where two or more functions can have the same name but different parameters. When a function name… Read More
  Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes.  The constructors of inherited classes are called… Read More
We have discussed a similar topic in Java here. Unlike Java, C++ allows to give more restrictive access to derived class methods. For example the… Read More
Predict the output of following C++ programs. Question 1 #include<iostream> using namespace std;    class Base  { public:     int fun()      { cout << "Base::fun() called";… Read More
Destructors with the access modifier as private are known as Private Destructors. Whenever we want to prevent the destruction of an object, we can make… Read More
Predict the output of following C++ program. Difficulty Level: Rookie Question 1 #include <iostream> using namespace std;    class A {     int id; public:     A… Read More
Static data members are class members that are declared using static keywords. A static member has certain special characteristics which are as follows: Only one… Read More
Default Arguments are the values provided during function declaration, such that values can be automatically assigned if no argument is passed to them. In case… Read More
C++ supports following 4 types of casting operators: 1. const_cast 2. static_cast 3. dynamic_cast 4. reinterpret_cast 1. const_cast const_cast is used to cast away the… Read More
To understand ‘this’ pointer, it is important to know how objects look at functions and data members of a class. Each object gets its own… Read More
When a variable is declared as a reference, it becomes an alternative name for an existing variable. A variable can be declared as a reference… Read More
Predict the output of the below code snippet. #include <iostream> using namespace std;    int i;    class A { public:     ~A()     {         i=10;     }… Read More
Copy elision (also known as copy omission) is a compiler optimization method that prevents objects from being duplicated or copied. It makes ‘returning by value’… Read More