>i heard that array are actually a pointer
You heard wrong. Arrays are often converted to a pointer to the first element, but in an object context, the two are different.
>what's wrong here ???
Your understanding of context. The Rule states that in value context an array name is converted to a pointer to the first element of the array. This is why subscripting is often compared to dereferencing a pointer offset. It's an expression with value context, so a[i] really does become *(a + i). Likewise, a function call is also a value context, so you can pass an array to a function that expects a pointer to the appropriate type:
Code:
void
foo(
int *p
)
{
cout<< *p <<endl;
}
int
main()
{
int a[] = {1,2,3,4,5};
foo(a);
}
So an array becomes a pointer to the first element of the array when in value context. Value context is everything except for two cases:
1) As an operand to the sizeof operator.
2) As an operand to the address-of operator.
For arrays, a third case where a string literal is used as an initializer for an array of char also exists. Arrays are not pointers or constant pointers or anything like that, they're arrays. However, in practical use arrays are closely related to pointers simply because they become pointers much of the time.