It sounds like you don't know about the stack and the heap. Your first example is just allocating some memory on the stack which will be deleted as soon as it goes out of scope. Memory on the heap which is obtained using malloc/new will stay around until you delete it using free/delete.