Leth Leth - 1 year ago 34
C Question

How can we set the parameter of an function as a pointer array, then call it by giving an array?

The structure should be like this:

int main()
int mainArray[12];


void func(int i,int *pointerArray[12])

So when I printed the 3th element of
function, it must give me 10.

How can I do that? What is the correct syntax?

Answer Source

You need to define the function like this:

void func(int i, int pointerArray[12])

The type of the pointerArray parameter needs to match the type of what was put in, namely mainArray. That type is int [].

In C, array indexes start at 0. That means the third element has index 2. So that's the index you use to set the third element.