arr1
and arr2
are pointers
No, arr1
is not a pointer. In particular, arr1
has type int [3]
, it's just that it decays to a pointer to its first element i.e., int*
in certain contexts due to type decay.
Is there any reason to use arr2 if its not going to get bigger or smaller during the code?
arr1
will be automatically destroyed when it goes out of scope while for arr2
you will have to free the memory(pointed by arr2
) manually. That is, you'll have to do manual memory management(not recommended).
Moreover, smart pointers should be preferred over raw pointers if/when you decide to use dynamically allocated memory.
Or better yet would be to use(if allowed) standard containers like std::vector
altogether etc.