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 |
WHAT IS THE ACTUAL DEFINATION OF OBJECT AND THE CLASS IN ONE SINGLE LINE WHICH THE INTERVIEWER WANT TO LISTEN.
You attempt to query the data base with this command: SELECT name, salary FROM employee WHERE salary=(SELECT salary FROM employee WHERE last name='Wagner' OR dept no=233) Choose most appropriate option from the following: 1)Sub-queries are not allowed in the where clause. 2)a multiple row sub-query used with a single row comparison operator. 3)a single row query is used with a multiple row comparison operator.
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
how do u initialize the constant variables
What is destructor example?
what is the difference between class to class type conversion and copy constructor ?
create a c++ program that will ask 10 numbers and display their sum using array.
What is ambiguity in c++
What is overriding vs overloading?
What is variable example?
What is the difference between pass by reference and pass by value?
What are the fields of vtable