I'm unsure why both the array of ptrs and the 'regular' arr both work, shouldn't the former array, it should be 'dereferenced' twice, once to pt the actual first address of first element and the second to access the actual content @ the first index?
Code:
int main()
{
int* arr_1[] = {1,22,3,55,6};
printf("%d\n", *(arr_1 + 1));//output: 22 (shouldn't it be dereferenced twice?)
/**VS*/
int arr_2[] = {1,22,3,55,6};
printf("%d\n", *(arr_2 + 1) );//same as arr_2[1]
return 0;
}
EDIT: I think I see it now. arr_1 holds ptr elems (so addresses of the literals) versus arr_2 stores the literals in the array and we have just ONE ptr (as oppose to multiple ptrs in arr_1) that pts to first elem, so it's like glass half full, half empty. We have individual ptrs to pt to where each literal is stored in arr_1 w/ a ptr that defaults to first elem that we can move to traverse arr_2. Of course this is trivial use of arr of ptrs, it be more useful to store an array of ptrs to objects (so structs or even arrays).
EDIT EDIT: I didn't notice that C is error prone unlike C++, I tried:
Code:
int* arr[] = {1,2,3}
in C++ and it didn't compile. Srry for all the trouble.