Function arguments - array of pointers or pointer to array ?

Hi,

Let's say we have following function declaration :

void print(int *kau[])

How do I tell whether kau[] is pointer to an array or an array of pointers ?
the array is turned in to a pointer when passed to a function so it would be a pointer to a pointer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void foo( int arg[] ) {} // type of arg: pointer to int

void bar( int* arg[] ) {} // type of arg: pointer to pointer to int

void baz( int (*arg)[3] ) {} // type of arg: pointer to array of 3 int

int main()
{
    int a[] = { 7, 8, 3 }; // array of 3 int
    foo(a) ; // ok, implicit conversion from array to pointer

    int* p[] = { a, a+1, a+2 } ; // array of 3 pointer to int
    bar(p) ; // ok, implicit conversion from array to pointer

    int (*pa)[3] = &a ; // pointer to array of 3 int
    baz(&a) ; // pass address of array
    baz(pa) ; // same as above
}
closed account (SECMoG1T)
1
2
3
4
int *kau[]/// here 
          kau [] //will store datatype of the  type left of kau , meaning int*
         int* // can be a pointer to int or an array of int as @gilbit and @JLBorges explained
        HENCE int * kau []  is equivalent to int **kau.
Last edited on
Topic archived. No new replies allowed.