[Solved] Using new on same veriable without using delete- c++


The operator new[] allocates size bytes of storage, suitably aligned to represent any object of that size, and returns a pointer to the first byte of this block. realloc changes the size of the memory block pointed to by ptr.

In your case, the first call on new[] operator creates a block, and then stores a pointer to it in variable a. The second call on new[] creates another block, and then stores the pointer to it in variable a. The block created from the first call is not destroyed.

If realloc is called, the existing block is resized and may be moved if needed. If the block is moved, the space allocated for the old block is freed.

solved Using new on same veriable without using delete- c++