The first creates a local automatic variable. This is (typically) stored on the function's stack frame, a block of temporary memory allocated (from the thread's stack) when the function execution begins, and released when the function returns. The object will be destroyed when it goes out of scope; that is, when the program leaves the current code block. This is usually how you want to create variables, unless you need them to live longer than that.
The vector
object itself, on the stack, is a fixed size. It manages a dynamic array of n
objects, allocated from the heap as described below. It automatically destroys that array, freeing its memory, when it is destroyed.
The second creates a dynamic object, from the program's free store (also known as the heap). This won't be destroyed until you explicitly do so:
delete list;
It's a very bad idea to deal directly with pointers to dynamic objects like this; it's very easy to leak the object (perhaps by returning from the function, or throwing an exception, and losing the only pointer to it), or to accidentally copy the pointer and try to delete it twice.
Hopefully, your tutorial book will teach you how to manage dynamic resources safely with smart pointers, and the general principle of RAII. If it doesn't, throw it away and get a better one.