Does anyone know how to pass an array of ints to a function?
i tried
and it didn't seem to work.Code:int a[2][2] = { {1, 2}, {3, 4} }; function(a); void function(int **a) { printf("%d\n", a[1][1]); }
Any suggestions?
This is a discussion on Array of ints within the C Programming forums, part of the General Programming Boards category; Does anyone know how to pass an array of ints to a function? i tried Code: int a[2][2] = { ...
Does anyone know how to pass an array of ints to a function?
i tried
and it didn't seem to work.Code:int a[2][2] = { {1, 2}, {3, 4} }; function(a); void function(int **a) { printf("%d\n", a[1][1]); }
Any suggestions?
> void function(int **a) {
Should be one of these - choose which is most readable
void function(int a[2][2] ) {
void function(int a[][2] ) {
void function(int (*a)[2] ) {
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
You could also do:
void function(int a[][])
Right, Salem?
1978 Silver Anniversary Corvette
> void function(int a[][])
> Right, Salem?
No, not right.
You can only leave the leftmost [] empty.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
I see. You can have:
But, doesn't that limit what you can do with something like this?Code:void function (int arr[]); /* legal */ void function (int arr[][2]); /* illegal */
--Garfield
1978 Silver Anniversary Corvette
Seems to work now.
Thanks