Difference between delete and delete[]?

Answer Posted / sachin mahajan

When we want to free a memory allocated to a pointer to an
object then "delete" is used.
Ex
int * p;
p=new int;
// now to free the memory
delete p;
But when we have allocated memory for array of objects like
int * p= new int(10); //pointer to an array of 10 integer
then to free memory equal to 10 integers
delete []p;
NOTE: One can free the memory even by "delete p;" But it
will free only the first element memory.


Is This Answer Correct ?    70 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.

1721


Explain the properties and principles of oop.

533


What is a namespace in c++?

602


What is constructor in C++?

632


What return value must conversion operators have in their declaration?

618






Why is "using namespace std;" considered bad practice?

653


What is c++ try block?

585


What is c++ stringstream?

611


Distinguish between a # include and #define.

653


What is the use of string in c++?

553


What are the stages in the development cycle?

577


Differentiate between an array and a list?

709


Is C++ case sensitive a) False b) Depends on implementation c) True

616


What is the use of turbo c++?

552


What is the operator in c++?

635