the difference between new and malloc

Answers were Sorted based on User's Feedback



the difference between new and malloc..

Answer / prakruthi

new automatically calls the constructor while malloc()
dosen't., also new being an operator, it can be overloaded.

since malloc returns a void pointer it is necessary to
explicitly typecast it into an appropriate type of pointer.
This gets completely avoided when we are using new operator.

Is This Answer Correct ?    25 Yes 2 No

the difference between new and malloc..

Answer / pushpankar mishra

malloc need type casting where as the new operator does not
require this incase if it is character type then char* is
needed in malloc where as for new we do not need this

Is This Answer Correct ?    10 Yes 1 No

the difference between new and malloc..

Answer / sanish joseph

both malloc and new functions are used for dynamic memory
allocations and the basic difference is: malloc requires a
special "typecasting" when it allocates memory for eg. if
the pointer used is the char pointer then after the
processor allocates memory then this allocated memory needs
to be typecasted to char pointer i.e (char*).but new does
not requires any typecasting. Also, free is the keyword used
to free the memory while using malloc and delete the keyword
to free memory while using new, otherwise this will lead the
memory leak.

Is This Answer Correct ?    13 Yes 8 No

the difference between new and malloc..

Answer / cl

The difference is the invocation of constructor: malloc
does not do it.

Is This Answer Correct ?    11 Yes 7 No

the difference between new and malloc..

Answer / swati

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.

Is This Answer Correct ?    4 Yes 3 No

Post New Answer

More OOPS Interview Questions

What is abstract class in oop?

0 Answers  


Can we have a private virtual method ?

8 Answers   Ness Technologies,


Prepare me a program for the animation of train

0 Answers  


What is namespace?

15 Answers  


#include <string.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> void select(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); select(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void select(char *items, int count) { register int a, b, c; int exchange; char t; for(a = 0; a < count-1; ++a) { exchange = 0; c = a; t = items[ a ]; for(b = a + 1; b < count; ++b) { if(items[ b ] < t) { c = b; t = items[ b ]; exchange = 1; } } if(exchange) { items[ c ] = items[ a ]; items[ a ] = t; } } } design an algorithm for Selection Sort

0 Answers  


Is html an oop?

0 Answers  


Should you protect the global data in threads? Why or why not?

2 Answers   IBM,


diff between Virtual mathod and abstract method?

1 Answers  


What are the benefits of polymorphism?

0 Answers  


Please send ford technologies placement paper 2 my mail id

0 Answers  


What is the difference between a mixin and inheritance?

0 Answers  


What is encapsulation c#?

0 Answers  


Categories