How do we delete a dynamically allocated array named `i`?

Options
- delete [0]i;
- delete []i;
- delete i[0];
- free(i);


CORRECT ANSWER : free(i);

Discussion Board
agree with writer

dynamic representation of array is
i = (int *)malloc(arraysize*sizeof(int));
to delete array call
free(i); in c

rahul 11-13-2014 09:33 AM

agreed with the comment

delete i; it will delete memory of first element of the array. To delete whole array we have to do delete []i .

pallavi 09-4-2014 02:59 AM

agreed

yes, definitely. That is a question for C++.

Federico 04-26-2014 01:53 PM

agreed

agree with the comment above

anonymouse 04-2-2014 10:52 PM

Deleting an array

This is a wrong question/answer for C for two reason:
(i) delete keyword is not C it is C++,
(ii) deleting an array in C++ is "delete [] i;"


abbas 11-26-2013 12:02 PM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement