C++ static_cast<void *>
c++, static-cast
Solution
It is because address of the variable `a` concides with the address of the first element of array `a`. You can also think of `a` is `&a[0]` which is clearer when we say "the address of the first element of the array").
Another example,
struct X
{
int i;
};
X x;
Here also the address of variable `x` concides with the address of `x.i` (which is the first element of the aggregate), so this would print `1`:
std::cout << (&x == &(x.i)) << std::endl; //1
So in your case, `&a` is like `&x`, and `a` (or `&a[0]`) is like `&(x.i)`.
Note that in C++ `a` and `x` are both called aggregate (see my answer here: What is an aggregate?)
Problem
Could someone explain this little code snippet for me? Given: ``` int a[3] = {2,3,4}; ``` Why does the following evaluate to true? ``` static_cast<void *>(a) == static_cast<void *>(&a); // Why is this true? ``` Is this saying that the `address of a` is the same as `a`? If so, why is this true?