Hello @tusharaggarwal20132013,
-
A memory leak occurs when programmers create a memory in heap and forget to delete it.
In this program, after executing the following code the compiler will lose access to the memory assigned at run time using malloc()
So, this leads to a memory leak.
-
Computers crash because of errors in the operating system (OS) software or errors in the computer hardware.
Reasons:
2.1. Segmentation Fault: It is the major reason for the program to crash. These are maybe the reasons for such cause:
- Attempting to access a memory location that doesn’t exist in our system.
- There may be an attempt to write on a read-only memory location.
- There may be an attempt to access protected memory location such as kernel memory
- Stack Overflow: There may case of non-terminating recursion with the memory location.
2.2. Buffer Overflow: It is an anomaly where a program while writing data to a buffer, overruns the buffer’s boundary and overwrites adjacent memory locations.
2.3. Exceptions
- Divide by zero.
Hope, this would help.
Give a like, if you are satisfied.