Answer Posted / praviss
An existing block of memory which was allocated by malloc() subroutine, will be freed by free() subroutine. In case , an invalid pointer parameter is passed, unexpected results will occur. If the parameter is a null pointer, then no action will occur.
Where as the realloc() subroutine allows the developer to change the block size of the memory which was pointed to by the pointer parameter, to a specified bytes size through size parameter and a new pointer to the block is returned. The pointer parameter specified must have been created by using malloc(),calloc() or realloc() sub routines and should not deallocated with realloc() or free() subroutines. If the pointer parameter is a null pointer, then no action will occur.
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
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
Why is static class not inherited?
What do you mean by overloading?
Why is object oriented programming so hard?
when to use 'mutable' keyword and when to use 'const cast' in c++
What is object-oriented programming? Webopedia definition
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
What is overriding vs overloading?
Why is oop useful?
Give an example where we have to specifically use C programming language and C++ programming language cannot be used?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
How long to learn object oriented programming?
hi all..i want to know oops concepts clearly can any1 explain??
What is object and class in oops?
What are the 4 main oop principles?