Answer Posted / 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 |
Post New Answer View All Answers
What do you mean by overloading?
What is abstraction with example?
Which is better struts or spring?
What is polymorphism what is it for and how is it used?
given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy
What is an advantage of polymorphism?
What is class and object in oops?
How to use CMutex, CSemaphore in VC++ MFC
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
What is polymorphism programming?
What is the difference between a mixin and inheritance?
Which language is not a true object oriented programming language?
What is inheritance write a program to show use of inheritance?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash