#include<iterator>
#include<iostream>
int a[5][4];
int main()
{
cout << *begin(a);
}
Why this cout will print the same as begin(a).
It seems the * does not dereferencing the pointer return by begin(a) ?
Can anyone tell me why?
>Solution :
Here * affects only the type of the pointer, and not its numerical value.
std::begin(a) returns a pointer to the first element of a, of type int (*)[4] (pointer to an array of 4 ints).
*std::begin(a) returns int[4]. Since cout can’t print arrays directly, the array then decays to the pointer to its first element, of type int *, and is printed as such.
**std::begin(a) would return an int.