What are the differences between new and malloc?



What are the differences between new and malloc?..

Answer / Mohammad Azeem Khan

new is an operator in C++ that dynamically allocates memory for objects, creates them, and initializes them. It automatically calls the constructor of the class being instantiated. On the other hand, malloc() is a library function in C that only allocates raw memory without constructing or initializing any object. To use malloc(), you must manually call the constructor.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is an action class?

1 Answers  


Explain overriding.

1 Answers  


Do you know what are static and dynamic type checking?

1 Answers  


Are strings immutable in c++?

1 Answers  


whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; };

5 Answers   Huawei,


write the prime no program in c++?

16 Answers  


When is the last time you coded in C/C++? What is the most lines of original C/C++ code you have personally written in one project? How confident are you in your ability to write C or C++ without a reference?

1 Answers   Microsoft,


Define the process of error-handling in case of constructor failure?

1 Answers  


Can I run c program in turbo c++?

1 Answers  


What is setfill c++?

1 Answers  


What is meant by a delegate?

1 Answers  


What is a manipulative person?

1 Answers  


Categories