Possible Duplicate:
Is array name a pointer in C?
If I define:
int tab[4];
tab is a pointer, because if I display tab:
printf("%d", tab);
the code above will display the address to the first element in memory.
That’s why i was wondering why we don’t define an array like the following:
int *tab[4];
as tab is a pointer.
Thank you for any help!
No,
tabis an array. Anint[4]to be specific. But when you pass it as an argument to a function (and in many other contexts) the array is converted to a pointer to its first element. You can see the difference between arrays and pointers for example when you callsizeof arrayvs.sizeof pointer, when you try to assign to an array (that won’t compile), and more.declares an array of four pointers to
int. I don’t see how that is related to the confusion between arrays and pointers.