+ 22

How to allocate data dynamically?

If u want to allocate data for your program dynamically...then how will u do?

17th Sep 2017, 11:05 AM
Sobin Benny
Sobin Benny - avatar
3 Respuestas
+ 7
In C, you use the malloc() function: char *c = malloc(20); Make sure to check for NULL return value (out of memory) and to use free() when you are done with the memory. In C++ and Java you use the 'new' operator. In C++ you need to free the memory using the 'delete' operator. In Java you don't need to free it, as the garbage collector will do it automatically for you.
17th Sep 2017, 11:17 AM
Udi Finkelstein
Udi Finkelstein - avatar
+ 7
In c++ for dynamic data allocation we use "new" keyword and to free that memory we use "delete" keyword. In java there is no need of dynamic memory allocation as the memory taken by object is already known.
17th Sep 2017, 11:18 AM
Lakshay
Lakshay - avatar
+ 3
C/C++ : pointers Python : nothing more than static Java : I am not sure but I think it is the same as Python
17th Sep 2017, 11:11 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar