Computer Science, asked by yumiko6515, 1 year ago

Point out the advantages of new over malloc( )

Answers

Answered by prathamesh1855
2
⛤Hey There⛤
_____________________________________________

Here is Your Answer


For the dynamic memory allocation we use New and malloc. Both are used to allocate memory But the major difference between New and Malloc are. 1. New is a operator where as Malloc is a function. 2.In case of Malloc we need to specify the size of memory for our data types. But in case of New we do not need to specify the size. ex. int *a; a=(int*)malloc(sizeof(int)); int *a; a=new int; answer one more difference is malloc return void* by default ,we need to typecast pointer returned from malloc but in case of new there is no need to typecast ex: int *a; a=(int*)malloc(sizeof(int)); a= new int; arun


Hope I Explained It Well.☺️


Similar questions