the difference between new and malloc
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Answer / cl
The difference is the invocation of constructor: malloc
does not do it.
Is This Answer Correct ? | 11 Yes | 7 No |
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 |
what is difference between objects and function
What exactly is polymorphism?
What is a class and object?
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
Whats oop mean?
What is class encapsulation?
How to call a non virtual function in the derived class by using base class pointer
What are the benefits of polymorphism?
How can i write a code in c# to take a number from the user and then find all the prime numbers till the number entered by the user.
What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.
what uses of c++ language?
How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?