Passing an Array to a Function

I don't fully understand why I'm getting this error for passing a 2d array to a function. Here is my code followed by the error. Any help is greatly appreciated.
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
27
28
29
30
31
32
#include <iostream>
#include <algorithm>
#include <ctime>

using namespace std;

void carrierLocationSet (int carrier[][4]);

int main()
{
	int carrier [4] [4];
	
	carrierLocationSet (carrier[4][4]);
}

void carrierLocationSet(int carrier[][4])
{
	int direction;

	srand (time(NULL));
	carrier [0][0] = rand() % 14;
	srand (time(NULL)+12);
	carrier [1][0] = rand() % 14;
	srand (time(NULL));
	direction = rand() % 4 + 1;

	for (int iteration = 1; iteration < 4; iteration++)
	{
		carrier [0][iteration] = carrier [0][0];
		carrier [1][iteration] = (carrier [1][iteration-1]) + 1;
	}
}


I'm getting this error:

1>c:\users\casey\documents\visual studio 2008\projects\battleship\battleship\battleship.cpp(13) : error C2664: 'carrierLocationSet' : cannot convert parameter 1 from 'int' to 'int [][4]'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

I don't understand what that means. Sorry I'm new to programming.
Last edited on
carrier[4][4]

This is an int, not the array (it is also out of range and is thus garbage). To pass the array, you simply use the name (carrier).
Last edited on
Topic archived. No new replies allowed.