1

Possible Duplicate:
Is array name a pointer in C?

I passed in an int * variable to a function which is defined as func(int var[]) and the compiler was complaining that passing in argument from incompatible pointer type. What's the difference, or is there no difference at all?

Community
  • 1
  • 1
mopodafordeya
  • 635
  • 1
  • 9
  • 26

1 Answers1

2

The function declarations R foo(T[]) and R foo(T *) are identical for all types T.

Your error lies somewhere else.

(You can call foo with either a pointer to a T or with the name of an array-of-Ts, since the latter decays to a suitable pointer during the call.)

Example:

void foo(int *);
void bar(int[]);

void example(int * a)
{
    int n = 10;
    int p[] = { 1, 2, 3 };

    foo(a);     bar(a);
    foo(p);     bar(p);    // all those are OK
    foo(&n);    bar(&n);
}
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084