 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can add all the elements of 2D array which is created dynamically in C++. Before starting you can note my information, you can connect with me by following these details which are available in front of you. Now coming on to the topic, you can see a code which is implemented in front of you. First statement is a comment which is showing some of the dynamic 2D array in C++ using new and delete operators. Then I have included a header file iostream. Then I have written a statement using namespace std. std is a predefined namespace available in iostream. It is used for seen and see out. Then a class arrays define inside this class a pointer to pointer p is declared of integer type and two variables go and columns are declared. Then in public section five functions are declared. First is set size, then destroy, then read, then print and then sum. Then class is terminated. After termination of class definitions of these functions are defined. So first a set size function is defined. Here void is written type array is name of class then scope resolution operator is available then set size is name of function then parenthesis. Inside this function see out statement will display enter rows and columns this message on console. Then number of rows and columns will be entered by the user in these two variables. Then this statement p equals to new int asterisk r. This statement will allocate memory blocks for number of rows. So here integer pointer type memory blocks will be allocated using new operator. Then a for loop is available which will allocate memory for columns. So this loop will create columns of integer type using new operator. So this loop will repeat r times. So if number of rows are three, so this loop will repeat three times. If number of rows are five then this loop will repeat five times. So with the help of these three statements the 2d array will be created of r and c values. Then second function destroy is defined. In this function memory is deallocated. Here for loop is implemented which is first deleting columns and then it is deleting all the rows. After destroy function read function is defined inside read function two variables i and j are declared then for loop which is repeating r times inside this for loop another for loop is implemented which is repeating c times column times. So with the help of this nested loop formation values of 2d array will be read from the user inside p matrix. Then print function is implemented which will display values of p of ij using this nested loop which which is already implemented in read function. So first loop is repeating r times, second loop is repeating column times. After this function some function is defined which is adding all the elements available inside p matrix into s. Same loop which are available in read and print are implemented here first loop is repeating r times second loop is repeating column times. After completion of these these two loops some will be stored inside s variable which is displayed using this cout statement. After completion of these function definitions main function is defined which is declaring an object of array class a1 then set size function is called then this message enter values will be displayed on console then a1 dot read this a1 object is calling read function to receive the values from user then a1 dot print print function is called to display the entered values on console then some function it is called to add all the elements which are available in matrix and then a1 dot destroy it will destroy the allocated memory with the help of delete operator. So this is the complete explanation now i am executing this code it is asking number of rows and columns so i have entered two rows and three columns now i am entering values i have to enter six elements so i am entering six times one you can see it is showing a matrix two by three size and it is showing the sum that is six so with the help of this program i have allocated dynamic memory for 2d array i have be allocated it i have read values from user i have displayed a matrix on console and i have displayed some using some function so i hope you have understood how you can add elements of 2d array in c++ and the array the 2d array is created dynamically using new operator and it is deallocated using delete operator if you want to watch more programming related videos you can subscribe my youtube channel thank you for watching this video