Question:
2d array in c++?
Cloud
2007-03-22 09:57:11 UTC
1/ how can I declare 2d array in c++? Is this correct?

########### CODE ###########
int **array;
array = new int * [rowsize] [columnsize];
................................
delete [ ][ ] array;
########### CODE ###########

2/ How can I get the rowsize and columnsize of a specified 2d array?
Three answers:
askMahesh
2007-03-22 10:08:10 UTC
Both decelerations are correct. All the following declarations are exactly same effect.



int **a;

int *a[];

int a[][];



Your other question is bit difficult. There is no way to do that. In C++/C



int a[5][10] and

int a[50]



are interchangeable. i.e. I can declare a[50] and access as a[3][4] and it will work same. You can use ("malloc" to allocate memory not defined through a[50]) "free" and pointer to release memory without knowing the size, But if you need the index for use in any other function then you will have to create variables to hold dimension.
2007-03-22 12:17:58 UTC
int a[2][3];

for(int i=0;i<2;i++)

{

for(int j=0;j<3;J++)

{

cin>>a[i][j];

}

}
turnbow
2016-11-28 03:31:25 UTC
right here is the answer : void considerable() { int n[3][10]; int i,j; cout<<"enter 30 numbers "; for(i=0;i<3; i++) { for(j=0;j<10;j++) { cin>>n[i][j]; } } for(i=0;i<3;i++) { cout<


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...