two-dimensional array

Started by
10 comments, last by UeberBobo 20 years, 5 months ago
quote:Original post by Plasmite
I used to do 2d-arrays with pointers to pointers. So that I basicly had arrays of arrays. I had a function declared like this
int function(char **parameter);
Everything worked fine. I usually declared my arrays like this
char **array;
and then alloacted memory for it. One day I tried this way of declaring the array
char array[5][10];
and I wasn''t sure wheter it would work, but I desided to try. I called the function like this
function(array);
and assumed, that if the array would be really just one array, 50 bytes long, my compiler would give me a warning. Compiler did not mention anything! And I assumed everything was fine, but the program did not work. Since my program did not work, I assume my array wasn''t really a array of arrays, (I guess this was correct, according to your discussion here). But I still wonder what my c-compiler was thinking about it? If I declare an variable like this:
char *variable;
I shouldn''t be able to put it as a parameter of function, if it is declared as
int function(char **array);
???

perhaps trying int function(char[][] array) would help, since in C++ the array type is slightly different than just being a pointer.

Advertisement
quote:Original post by UeberBobo

then shouldnt myArr[3][1] = myArr[(3*3)+1] = myArr[10] = myArr[2][4] = myArr[(2*3)+4] = myArr[10]?

cuz thats why i thought they would be the same

[edited by - ueberbobo on November 18, 2003 1:13:58 PM]


Yeah, but your array is only three wide, so your myArr[2][4] is overflowing onto the next row. So it is myArr[3][1].

This topic is closed to new replies.

Advertisement