 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can implement dynamic 2D array using constructor and destructor in C++. Before starting, you can note my information. You can connect with me by following these details. You can download my app Takimis based on programming languages from Google Play. You can search my channel by typing my name on YouTube search. My channel will be available there. You can visit my channel. You can subscribe my channel if you want to follow my videos. Here various programming language related videos and playlists are available. You can follow them. Now coming on to the topic. You can see a comment dynamic 2D array using constructor and destructor is written. Then I have included a header file IO stream. Then STD namespace is used. Then a class name is matrix. Inside matrix class, I have declared three attributes. One is P pointer to pointer. Then R and C are normal variables. Then you can see I have implemented a constructor. In this program, constructor is dynamically allocating memory for a matrix. So first it is reading rows and columns from user using these C out and scene statements. Then memory will be allocated for rows and memory will be of integer pointer type. So beginning address will be assigned into P. Then using this for loop, individual columns will be created. Here memory will be allocated for integer type and size will be C. So you can see first number of rows will be created and for each row, number of columns will be created by this loop. After execution of this constructor, destructor is defined. Inside destructor, first all columns are destroyed and after completion of this loop, all number of rows which are allocated to P will be deleted. So constructor is allocating memory dynamically and destructor is deallocating dynamically allocated memory. Then read and print functions are declared. After termination of class, you can see first read function is defined. So read function is reading values inside P of ij using these two nested loops. First is repeating r times and second is repeating column times. Then print function, again it is having two nested loops. First is repeating number of rows times and second is repeating column times. Then it is displaying values of P of ij on console. This handle is used because I want to display values and metrics from it. So after completion of inner loop, that is j loop, line will be changed and next row will be displayed in new line. After reading and printing functions, main function is implemented. Here an object M is created. So whenever this object is created, constructor will be called automatically. Then see out, enter elements. This message will be displayed. Then read function is called through M object. So all the elements will be entered by the user. Then this message you have entered will be displayed and print function will display all the elements which is entered by the user on console. After termination of main function, destructor will be called automatically and all the memory blocks created by new operator will be destroyed. So friends, I hope you have understood how you can use constructor and destructor for dynamic memory allocation and deallocation respectively. Now I am executing this code so that you can understand it is working properly. I have passed number of rows and columns 2, 2 and I am entering four times because I have to enter four elements. You can see the output. Output is displayed in matrix format and number of rows and columns are 2, 2. So friends, this way I have created dynamic 2D array using constructor and destructor in C++. If you want to watch more programming related videos, you can visit my channel on YouTube that is sanjagopta underscore tech school. You can search it by my name only. Here various programming related videos and playlists are available. Thank you for watching this video.