-
Arrays in functions
How would i use an array ( that is defined in the main() ) in a function? how would i define it?
for example:
Code:
void Function( int grid[4][4] );
int main()
{
int array[4][4];
Function(array[4][4]);
return 0;
}
void Function( int grid[4][4] )
{
printf(" %d %d %d %d\n %d %d %d %d\n %d %d %d %d\n %d %d %d %d\n", grid[0][0], grid[0][1], grid[0][2], grid[0][3], ... , grid[3][3]);
}
this is a watered down version of what im working on, but i need array[4][4] to equal grid[4][4], and all the numbers in the arrays to match up. is this even possible? or will i have to copy and paste the printf line throughout my code whenever it is needed?
-
You have it almost nailed down . . . you just need to call the function like this:
You see, Function takes a variable of type int [4][4]. "array" matches that type. But "array[4]" is of type int[4], and "array[4][4]" is of type int, never mind that both of those indices are out of bounds. :)
-
Thanks alot for the quick reply :D