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
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.
Explain the properties and principles of oop.
What is a namespace in c++?
What is constructor in C++?
What return value must conversion operators have in their declaration?
Why is "using namespace std;" considered bad practice?
What is c++ try block?
What is c++ stringstream?
Distinguish between a # include and #define.
What is the use of string in c++?
What are the stages in the development cycle?
Differentiate between an array and a list?
Is C++ case sensitive a) False b) Depends on implementation c) True
What is the use of turbo c++?
What is the operator in c++?