Firstly, I support the other's suggestions to avoid new and use std::vector instead. std::vector saves many headaches caused by pointers and arrays. Arrays are very much a C solution, not a C++ solution.
To answer your question: you do not need a pointer-to-pointer type here. The reason is that arrays are naturally addressed by pointer.
When you say t = new temp[100];
two things happen:
- A new array is allocated from the free store (or 'heap')
t
is set to point to the new array's first element.
When you use the p[i]
operator, it is actually syntactic sugar for *(p + i)
. For example:
t[0]
is equivalent to *(t + 0)
which is just *t
, or the element that t
points at: the first element of the array.
t[1]
is equivalent to *(t + 1)
. Since t
is a pointer to the first element of the array, t + 1
is a pointer to the element one place beyond the first: the second element. So *(t + 1)
gives you the second element.
Using this system, a temp *
pointer can be used to refer to a whole array of temp
, instead of just a single temp
instance.
If you really want to learn about arrays and pointers, you could do worse than read chapter 6 of the comp.lang.c FAQ. Note, however, that this is a C resource, not a C++ resource; this is because in C++, arrays are generally not used because you have a better feature available: std::vector. I strongly recommend you make learning about std::vector a higher priority than learning about pointers and arrays.