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
Show the application of a dynamic array with the help of an example.
Why can’t you call invariants() as the first line of your constructor?
What ANSI C++ function clears the screen a) clrscr() b) clear() c) Its not defined by the ANSI C++ standard
What are the sizes and ranges of the basic c++ data types?
what are the types of Member Functions?
Can you declare an array without a size in c++?
What is setiosflags c++?
Write a program which is required to process the time of a clock in hours and minutes, entered from the keyboard. With this program, there are two requirements for any data entered by a user: 1. The data must be of the correct type (in this case, two ints). 2. The data must be in the correct range: this means that, for the minutes, negative numbers and any number above 59 must be rejected; for the hours, negative numbers and any number above 23 must be rejected. Output error message for invalid data input. Output the time one and a half hour after the time input. i.e. Hour: 22 Min: 32 One and a half hour after 22:32 is 00:02
What is the difference between map and hashmap in c++?
Can we declare a base-class destructor as virtual?
When should I use unitbuf flag?
What is insertion sorting?
Is atoi safe?
Why c++ is the best language?
How many types of modularization are there in c++?