Possible Duplicate:
gcc compile error: cast specifies array type
I want to check the difference in (int * ) and (int []). When I compile the following code, line one goes fine. But for line 2, my compiler gives the following error:
test.c:10: error: cast specifies array type
Can any one please tell me the meaning of this error and where have I erred?
#include<stdio.h>
void abc(int *a)
{
int i;
for(i=0;i<2;i++)
{
printf("%d",((int * )a)[i]); //(1)
printf("%d",((int [])a)[i]); //(2)
}
}
int main()
{
int b[2]={0,1};
abc(b);
return 0;
}
In general
int *is a pointer (to an integer) andint[]is an array of unspecified size, which is a so called incomplete type. Incomplete types can only be used in declarations and must be completed in definitions. For example (the following code lies in global scope):When you talk about function parameters, it’s a whole other story. The declarations:
and
will be identical. It’s just syntactic sugar if you will.
Edit: Other than that: If you are asking what’s the difference between arrays and pointers: Everything! I’d link you to C-faqs.com for more concrete answers.