C++ New And Delete Question:
Download Questions PDF

Can you please explain the difference between new and malloc and delete and free()

Answer:

Delete is assocated with new and free(0 is associated with malloc()

New
Its an operator
delete is associated with new
It creates an object
It throws exceptions if memory is unavailable
Operator new can be overloaded
You can state the number of objects to be created.

malloc()
It’s a function
free() is associated with malloc()
It does not create objects
It returns NULL
This cannot be overloaded
You need to specify the number of bytes to be allocated.

Download C++ New And Delete Interview Questions And Answers PDF

Previous QuestionNext Question
Explain realloc()?Which of the following is a valid array declaration?

select one:
a. char[] c = new char[5];
b. char[] c = new char[];
c. char c = new char();
d. char[] c = new char(4);?