Lately I started learning pointers and references in c++ (not just the usual use of them,but all kinds of ways,I don\'t want to have problems with them in near future).
t
is a pointer declared on the stack which holds the address of an array on the heap. &t
gets the address of t
, AKA the location of t
on the stack. If you want to access the first member of the array, you can either do *t
or t[0]
. C++ automatically dereferences and does pointer arithmetic based on the type of t
when you use the bracket notation.
However, &t[0]
essentially gets you the address of t[0]
, which is why it is different from &t
, as &t
lives on the stack while &t[0]
lives on the heap. So if you want the address of t[0]
, you can use that notation, otherwise stick to t[0]
if you just want the values.