+ 1
how to reallocate memory in c++?
int *a; a = new int[5]; a[0] = 5; cout<< a << " " << a[0] << endl; a = new int[10]; cout<< a << " " <<a[0]; In the above code both the output of a and a[0] are different for both of the outputs. In C, we use realloc function to dynamically reallocate memory. As I used new int[10] second time it didn't reallocate memory, it allocates memory in different location instead.
0 Réponse