What is difference between new and malloc?
Answers were Sorted based on User's Feedback
the difference between malloc and new is just that when a
variable is declared using malloc, it requires type casting
while new operator whenever used does not type cast by
itself as there is no need for the variable to be typecasted
when used with new operator
Is This Answer Correct ? | 11 Yes | 0 No |
Answer / shivi jain
new and delete are C++ specific features. They didn't exist in C. malloc is the old school C way to do things. Most of the time, you won't need to use it in C++.
malloc allocates uninitialized memory. The allocated memory has to be released with free.
calloc is like malloc but initializes the allocated memory with a constant (0). It needs to be freed with free.
new initializes the allocated memory by calling the constructor (if it's an object). Memory allocated with new should be released with delete (which in turn calls the destructor). It does not need you to manually specify the size you need and cast it to the appropriate type. Thus, it's more modern and less prone to errors.
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / vivin
malloc is a dynamic memory allocation for pointers in C language. It stands for memory allocation. It is used to allocate continuous block of memory.
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / vivin
new is a operator used for memory allocation in c++ & java
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / devi
In C the malloc is used to allocate the memory space
In C++ the new operator is used to allocate the memory space
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / amri
When we use macro its need typecasting but in new not need of typecasting.
new is a operator.
Is This Answer Correct ? | 0 Yes | 3 No |
Answer / sanjeevkumar.v
malloc --it mean memmory allocation .it will be.crete a
memory from a element
NEW--- newly crate a program are crete a memory allocation
Is This Answer Correct ? | 1 Yes | 10 No |
What is the real life example of polymorphism?
write a progra in c++ using class & object to find out wheather a given no. is prim or not.
Can bst contain duplicates?
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
pointers are support in C#? if yes then how to use it?
8 Answers Softvision Solution,
what is overloading and overriding?
different types of castings
write a function that takes an integer array as an input and finds the largest number in the array. You can not sort array or use any API or searching needs?
2 Answers IBMS, Zycus Infotech,
What are the benefits of interface?
can we make a class static without using static keyword?
What is difference between function overloading and overriding?
Write a program to multiply 3x3 matrics