c and c++ programming difference-VII

@angnima (772)
Nepal
March 4, 2007 12:33am CST
c and c++ programming difference-VII: Freeing arrays: new[] and delete[] In C, there's only one major memory allocation function: malloc. You use it to allocate both single elements and arrays: int *x = malloc( sizeof(int) ); int *x_array = malloc( sizeof(int) * 10 ); and you always release the memory in the same way: free( x ); free( x_array ); In C++, however, memory allocation for arrays is somewhat different than for single objects; you use the new[] operator, and you must match calls to new[] with calls to delete[] (rather than to delete). int *x = new int; int *x_array = new int[10]; delete x; delete[] x;
1 response
@dholey (1383)
• India
1 May 07
in c we have malloc calloc and realloc ... for memory location and free to make memory deallocation in c++ new and delete keywords are given the difference between delete x and delete [] x is ... the second one releases the whole array where the first one will release only one variable ...