We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
new is for dynamic memory allocations. It create namless variables stored in the heap. He created a nameless array that can change size in runtime. Unlike normal array, N doens't need to be constant. The variables stored in the stack are destroyed once the program reach the end of their scope, while the heap variables don't. Therefore, they need to be explicitly delited to free memory. That's why he put delete[] a; at the end.
Arrays Introduction
You are viewing a single comment's thread. Return to all comments →
new is for dynamic memory allocations. It create namless variables stored in the heap. He created a nameless array that can change size in runtime. Unlike normal array, N doens't need to be constant. The variables stored in the stack are destroyed once the program reach the end of their scope, while the heap variables don't. Therefore, they need to be explicitly delited to free memory. That's why he put delete[] a; at the end.