Difference between realloc() and free?

Answer Posted / alka

free()is a macro used to deallocate memory.
when we need more memory realoc() reallocate memory
according to given size, if there is no memory 4
alocation ,it will free previous allocated memory &
allocate new one using malloc().
ex: int *p = realloc(p,sizeof(p)*2);

Is This Answer Correct ?    15 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is pure oop?

597


How is class defined?

588


What is oops and why we use oops?

573


What is the renewal class?

2167


What is class in oop with example?

621






What are classes oop?

598


What are the components of marker interface?

602


What is the example of polymorphism?

558


What is the difference between a mixin and inheritance?

522


Give two or more real cenario of virtual function and vertual object

1851


What is overriding vs overloading?

584


Is oop better than procedural?

574


Do you know about multiple inheritance?

641


What is polymorphism oop?

623


Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation

1660