Functionmallocreturns a piece of continuous memory that's all. How you type and use text (for your objects) is your problem.
While the operator newreturns the objects allocated in memory. Although both return a pointer, in the end you get constructed objects, not raw memory in C ++. Here, the focus shifts from low-level memory processing to processing objects with which type safety arises. Reason newdoes not return void*.
, , C, , , . ++ new , , , , . , , , , , .
:
int *ptr = malloc(sizeof(char) * 4);
, 4, , . char int , C. , , malloc , , ptr. , , ( ?) . , .
++
int *ptr = new char[4];
; int *ptr = new int;, . ++ , , , , . , , ++. casting : . ( , ).