CONSTRUCTOR & DESTRUCTOR
WRITE A PROGRAM IN CLASS THAT CAN STORE AN INTEGER ARRAY OF DIFFERENT WITH FOLLOWING MEMBER FUNCTIONS A) CONSTRUCTOR WITH ARRAY SIZE =0 B) COPY CONSTRUCTOR C) DESTRUCTOR #include <iostream> class arr{ int a[100],size; public: arr(){ std::cout<<"CONSTRUCTOR INITIALIZED ARRAY SIZE TO 0"; size=0; a[size]; } arr(arr &x); ~arr() { std::cout<<std::endl<<"DESTRUCTOR INVOLVED ~~ FREE MEMORY"; } }; arr::arr(arr &x) { std::cout<<std::endl<<"COPY CONSTRUCTOR INVOLVED"; size=x.size; a[size]; for(int i=0; i<x.size; i++) { a[i]=x.a[i]; } } int main() { arr a1; arr a2(a1); } INPUT-OUTPUT: CONSTRUCTOR INITIALIZED ARRAY SIZE TO 0 COPY CONSTRUCTOR INVOLVED DESTRUCTOR INVOLVED ~~ FREE MEMORY DESTRUCTOR INVOLVED ~~ FREE MEMORY This article is updated every month. Bookmark this for more interesting posts.