What is a copy constructor? What is a destructor? How do you implement them? Als
ID: 3806454 • Letter: W
Question
What is a copy constructor? What is a destructor? How do you implement them?Also when working with pointers what is the difference btw * and ->?
From my understanding * declares a pointer and -> access a element of linked list. Is this correct?
What is a copy constructor? What is a destructor? How do you implement them?
Also when working with pointers what is the difference btw * and ->?
From my understanding * declares a pointer and -> access a element of linked list. Is this correct?
What is a destructor? How do you implement them?
Also when working with pointers what is the difference btw * and ->?
From my understanding * declares a pointer and -> access a element of linked list. Is this correct?
Explanation / Answer
1. copy constructor:
it is a member function whixh is ued to intialize the object using other object of same class.
If copy constructor is not defined in the class compiler it self create ones.
2. Destructor:
A destructor is member function of class which is used to execute whenever an object of the class out of scope.
IT is very useful releasing resources before program exit means closng files, deallocate memories etc..
3. The * is used to get the value of the sane pointer. this * operator is known as Value at operator
Consider x is pointer storing address of memory then *x is value at specified memory location.
the opertor -> is only used with structure pointer. in order to access structure members -> operator is using.
Ex- suppose, x is a structure pointer.
Then you can get a member this way:
*(x).a
Or
x->a
So, -> is just a shortcut with structure pointers.
no -> is not for linked list it is used to access structure memebrs like student structure sid, sname sage while these memebrs are pointers then -> operator is used.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.