Answer to Question #262103 in C++ for Rohit Swain

Question #262103

Demonstrate how copy constructor is called during pass by value and return by value using C++ programme.


1
Expert's answer
2021-11-07T10:13:27-0500
#include <iostream>  
  
using namespace std;  
  
class Test  
{  
    int x;  
    int y;  
    int *z;  
    public:  
    Test()  
    {  
        z=new int;  
    }  
    void input(int a,int b,int c)  
    {  
        x = a;  
        y=b;  
        *z=c;  
    }  
    void output()  
    {  
        cout << "The value of x is : " <<x<< std::endl;  
        cout << "The value of y is : " <<y<< std::endl;  
        cout << "The value of *z is : " <<*z<< std::endl;  
    }  
};  
int main()  
{  
  Test t1;  
  t1.input(20,5,7);  
  Test t2 = t1;  
  t2.output();  
    return 0;  
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS