What is Copy constructor In C++ in Hindi

What is Copy Constructor in C++ Explain With Example in Hindi:- Hello Friends Mera Naam Shubham Hai, & I am Back With QA Series of c++ and today’s topic is What is Copy Constructor in C++ in Hindi.

What is Copy constructor In C++ in Hindi

What Is Copy Constructor in C++ in Hindi

Copy Constructor Ek Aisi process hai jiska use karke ek object ko kisi dusre object ke dwara create Karne ke liye kiya jata hai. “it means It’s a process When a new object is created from an existing object is Called Copy Constructor.” Copy Constructor me arguments ke roop me object ko pass Kiya jaata hai & old Object ki Value new object me Copy ho jati hai. Ager Class me Copy Constructor Define Nahi Kiya hai to Compiler Khud hi Use Create kar leta hai, Jise Default Copy-Constructor Kaha Jata hai.

Use of copy constructor in c++ in Hindi

  • same class me ak object ke dwara dusre object ka initialization Karne Ke Liye Copy Constructor Ka Use Kiya Jata hai.
  • Object ko As a function Value returnKarnee ke liye.
  • Function se return aane per Object ki Value Copy karne ke liye Bhi Copy Constructor ka use Kiya jata hai.

Here Is Example Of Copy Constructor in Hindi

#include<iostream.h>

#include<conio.h>

#include<string.h>

class bank

{private:

int ano;

char name[20];

int bal;  

public:

void get()

{ cout<<“Enter account no= “;      cin>>aon;

cout<<“Enter Name= “;    cin>>name;

cout<<“Enter Balance= “;     cin>>bal;

}    void show()

{  cout<<ano<<“\t”<<name<<“\t”<<bal<<“\n”;

}  

bank()

{ano = 15050;

strcpy(name , “Ravi”);

bal = 60000;

}

bank (bank & r)

{

ano= r.ano;

strcpy(name, r.name);

bal= r.bal;

}  };

void main()

{ clrscr();

bank b1;

b1.get();

bank b2(b1);

b2.show();

getch();

}

Iss program Me pahle Hamne Constructor ko Create Kiya. Uske baad ‘r’ Ke reference ka use karke pahle b1 object Se get() function ko access Kiya fir b1 Se b2 me constructor copy karke b2 object ko show() function ko access kiya.

To More Info About Copy Constructor Watch this Video.

Video Credit: easytuts4you

Thank For Reading This Post, If this Post is Helpful For You Then Please Share With Your Friends.

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.