C program to allocate memory dynamically for 2-d array, C/C++ Programming

Aim: To implement a program to allocate memory dynamically for 2 dimensional array (accept and print matrix) using pointers.




class matrix


            int **p,r,c,i,j;




                        void getdata();

                        void display();


matrix::matrix(int x,int y)




            p=new int *[r];


                        p[i]=new int [c];





                        delete p[i];

            delete p;

            cout<<"\nMemory deallocated successfully\n";


void matrix::getdata()


            cout<<"\nEnter matrix values:\n";



                        cout<<"Enter values for row:"<





void matrix::display()


            cout<<"\nThe matrix is:\n";








void main()


            int rows,cols;


            cout<<"Enter number of rows and columns for a matrix\n";

            cout<<"Enter number of rows\n";


            cout<<"Enter number of columns\n";


            matrix A(rows,cols);






Enter number of rows and columns for a matrix

Enter number of rows                                                           


Enter number of columns                                                        


Enter the values of the matrix                                                 

Enter values for row 1                                                         

1 2 3                                                                          

Enter values for row 2                                                         

4 5 6                                                                           

Enter values for row 3                                                         

7 8 9                                                                          

The matrix is                                                                   

1       2       3                                                              

4       5       6                                                              

7       8       9                                                               

Memory deallocated successfully

Posted Date: 9/29/2012 4:12:36 AM | Location : United States

Related Discussions:- C program to allocate memory dynamically for 2-d array, Assignment Help, Ask Question on C program to allocate memory dynamically for 2-d array, Get Answer, Expert's Help, C program to allocate memory dynamically for 2-d array Discussions

Write discussion on C program to allocate memory dynamically for 2-d array
Your posts are moderated
Related Questions
Define a user-defined data type (struct) called Car to represent a car in the context of a car dealership database. Car must have at least the following characteristics: Make Model

input marks of c and c++ if c grater than equal to 50 grater than 50 you are pass if c greater than equal to 50 c++ less than 50 than supplementry c++ if c less then 50 and c++ gra

I want VLC Pitch Changing Addon Project Description: Required: Plugin to modify the pitch of running tracks in VLC without changing the speed. Skills required are C Progra

: Write a program that prompts the user to enter five digit positive numbers. The program then outputs the digits of the number one digit per line. Eg if the user enters 32456, th

Classify computer systems according to capacity. How they are different from computers according to the classification of technology. Provide comparative study also.

Project Description: I am seeking someone who can make this modem work with Linux Caller ID on Ubuntu present stable version. Skills required are C Programming, Python

finds the average for all assignments for an individual student float getAverageForStudent(float scores[20][10], int student, int numAssignments) {  }  // finds the average for

C program to demonstrate Pointer to array: void p2a(int *); void main() {                 int x=10, *a,**b;                 int arr[5];                 a=&x;//po

Type Casting Implicit type conversions, as allowed by the language, can lead to errors creeping in the program if care is not taken. Thus, explicit type conversions may be used

Assume variables x, f, and d are of type int, float, and double, respectively.  Their values are arbitrary, except that neither f nor d equals +∞, -∞, or NaN .  For each of the fo