![]() |
VOOZH | about |
In this article, we will discuss the reason for the run-time error and its solution. Runtime Error: A runtime error in a program is an error that occurs while the program is running after being successfully compiled. Below are some methods to identify the reason behind Runtime errors:
Method 1: When the index of the array is assigned with a negative index it leads to invalid memory access during runtime error. Below is the C++ Program to illustrate the invalid memory access during run-time:
1736487104
Method 2: Sometimes Array or vector runs out of bounds of their limits resulting in a runtime error. Below is the C++ program illustrating array runs out of bound:
Output: 👁 Image
Explanation:
Method 3: Some silly mistakes like dividing by zero encountered while coding in a hurry, sometimes leads to runtime error. Below is the C++ program illustrating runtime error by dividing by zero and un-assigned variables:
Output:
Output: 👁 Image
Explanation:
The above program shows "Bad memory access (SIGBUS)" because: