+ 22
How to allocate data dynamically?
If u want to allocate data for your program dynamically...then how will u do?
3 Answers
+ 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.
+ 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.
+ 3
C/C++ : pointers
Python : nothing more than static
Java : I am not sure but I think it is the same as Python