If you write int arr[] = {20,3,2,0,-10,-7,7,0,1,22};
your arr
is usually stored on the stack, just like int a=20, b=3, ...;
. In this case, the right-hand side is an initializer, which just tells how int arr[]
is initialized.
On the other hand, if you write int *arr = new int[]{20,3,2,0,-10,-7,7,0,1,22};
the array is created on the heap, which can only be accessed via pointers, and the pointer pointing to the array is assigned into int *arr
which in turn is on the stack.
So in the context of declaration, int[]
and int*
are completely different things. But both int[]
array and int*
array can be accessed using the []
operator, e.g. arr[2]
which is synonymous with *(arr+2)
. And when you use int[]
or int*
as an argument of a function, they are completely interchangeable.