What is difference between new and malloc?

Answers were Sorted based on User's Feedback



What is difference between new and malloc?..

Answer / harsh

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

What is difference between new and malloc?..

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

What is difference between new and malloc?..

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

What is difference between new and malloc?..

Answer / vivin

new is a operator used for memory allocation in c++ & java

Is This Answer Correct ?    3 Yes 0 No

What is difference between new and malloc?..

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

What is difference between new and malloc?..

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

What is difference between new and malloc?..

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

Post New Answer

More OOPS Interview Questions

Write A Program using Single and Multiple Inheritance.

1 Answers  


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

0 Answers  


Why do we use oops?

0 Answers  


The IT giant Tirnop has recently crossed a head count of 150000 and earnings of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate. Suppose 14 such programmers take 14 minutes to write 14 lines of code in total. How long will in take 5 programmers to write 5 lines of code in total ?

6 Answers   TCS,


c++ program to swap the objects of two different classes

0 Answers  






What is polymorphism? Explain with an example.

48 Answers  


Name an advantage of linked list over array?

11 Answers   IBM, Infosys,


1.explicit call for destructor 2.calling function inside a constructor. 3.base *b-new derived delete b; 4.delete p what it will delete. 5.size of base class and derived class int i,in base class and int j in derived. 6.int i-20 int main() { int i =5; printf("%d".::i); { int i =10; printf("%d".::i); } } 7.object slicing 8.new 9.function overloading(return type). 10.class base() { virtuval fun() { ----- } } class derivied:public base() { fun() { ----- } } int main() { derived d; } 11.how static function will call in C++? 12.default structures are in C++? 13.constructors should be in public . 14.virtuval constructor not exist. 15.multilevel inhritence. destructor order.

1 Answers   Tech Mahindra,


If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?

0 Answers  


Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

0 Answers   TCS,


What is the difference between Home and $Home?

2 Answers   TCS,


What is OOPS and How it is different from Procedural Programming ?

23 Answers   HP, Infosys, Thyrocare,


Categories