Passing arrays between functions.

First, let me say that I've tried Googling this multiple times, but only seem to find info on passing an array from main to a function, which I'm not having a problem with. My problem is when I pass an array to a function, then try to pass the array from that function to another function. Here is a simplified version of my problem:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "stdafx.h"

void function1(int);
void function2(int);

void function1(int intArray[2][3])
{
	// do some work on the array

	function2(intArray);		// error C2664: 'function2' : cannot convert parameter 1 from 'int [][3]' to 'int'
}

void function2(int intArray[2][3])
{
	// do some work on the array
}

int _tmain(int argc, _TCHAR* argv[])
{
	int intArray[2][3];

	function1(intArray);
	function2(intArray);		// same code, no errors with this line

	return 0;
}


I'm guessing that this has something to do with pointers which I'm still having a bit of difficulty with. As I understand it, the array is not actually passed, but a pointer to it is. But then why is there a problem passing that pointer from function1 to function2? Is this what's called array decay? Why does the function call work fine in the main function but not in function1?
The function prototypes at lines 3 and 4 don't match the function definitions.
3
4
void function1(int [][3]);
void function2(int [][3]);
Ah! Thanks for the help. The problem was with the function prototypes and not the functions themselves. I get it now!
Topic archived. No new replies allowed.