The use of dynamic memory in C and C + + is different, in C language to use dynamic memory to include a header file that is #include <malloc.h> or #include < Stdlib.h> then uses the C language system function void * malloc (usigned size) to obtain dynamically allocated memory, the function parameter is the number of bytes of memory that needs to be requested, and returns the first address of the requested memory. The type of memory returned is void, so you need to force the type conversion as needed, such as int *array; array= (int *) malloc (sizeof (int) *10), so you can apply dynamically to a 10 The memory space of the INT type variable.
But in C + +, it seems that the statement used is simpler, including the header file is #include <iostream.h> application memory does not need to call the function as long as a keyword new. e.g. int *array; array=new int[10]; Note that int *array=new int (10) is not a space to apply for 10 int, but an int-type memory space, and then assigns him a value of 10. Of course, if you use int *a; a=new int, then you get a memory space that can hold int data.
C and C + + Dynamic request memory is freed before the program exits,C uses the free () function, and C+ + uses the delete keyword.
Dynamic application of memory in C and C + +