What is memory leak and memory corruption?
Answer / shyamal bose
Memory leaks happens for the memory allocated on Heap(ex A
*temp = new A()) . memory allocated by us on stack (int a)
is released automatically when the function returns or
module goes out of scope.
But memory allocated on heap will not be freed
automatically, we need to release it manually.
ex:
func()
{
A *a = new A(); //on heap
int b; // on stack
}
main()
{
func();
}
Now in above example when func is called memory for "a" is
created on HEAP by using NEW, but it is not freed by using
DELETE, hence is memory leak. On the other hand "b" is
created on STACK & freed automatically. so correct
implementation is:
func()
{
A *a = new A(); //on heap
int b; // on stack
delete a; //deleting memory on heap
}
main()
{
func();
}
Is This Answer Correct ? | 7 Yes | 0 No |
DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.
What are the different forms of polymorphism??
how to get the oracle certification? send me the answer
What is the difference between class and object?
swapping program does not use third variable
This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line preceded by a line number. Print the line number right-adjusted in a field of 3 spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior if the line is too long (i.e., wrap or truncate). A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.
What is advantage of inheritance?
Child cObj = new Parent() Wahts the output ?
Write a program to find out the number of palindromes in a sentence.
Is oop better than procedural?
What is encapsulation oop?
for example A,B,C,D are class all the 4 class contain one method who() but the method who() implementaion is differnet among each class. the relation among the 4 class are A is base class and is inherited by B and C.and from this two B and C where D is inherited. the question is i want to display the output who() method in all the classes(A,B,C,D)the output of who() method is diferrent amond all the class(A,B,C,D) ------A------ virtuval who(print a) override | | who(print b) B C override who(print c) | | -------D------ override who(print d)