Basic Program of Copy Constructor || Copy Constructor || C++
In this, we are going to see a Basic Program of Copy Constructor in C++.



#include <stdio.h>>
using namespace std;

class Value
{
public:
    int val;

    Value(int x)
    {
        val = x;
    }

    Value(const Value &obj)
    {
        val = obj.val;
    }
};

int main()
{
    int x;
    cout << "Enter the Value: ";
    cin >> x;
    Value obj(x);
    Value obj1(obj);
    cout << "value of 'val' copied from obj: " << obj1.val;
    return 0;
}

//..........Coded by SAHIL SHAIKH

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post