C Program to Show Runtime Exceptions Last Updated : 03 Aug, 2022 Comments Improve Suggest changes Like Article Like Report Runtime exceptions occur while the program is running. Here, the compilation process will be successful. These errors occur due to segmentation faults and when a number is divided by a division operator or modulo division operator. Types of Runtime Errors:An invalid memory access Dividing by zero. Segmentation faults Large memory allocation/Large Static Memory Allocation Making common errors. 1. During runtime, an invalid memory access An invalid memory access error occurs during runtime when the array's index is assigned a negative value. Note: The output might change every time we run this program because it gives a junk value in return for the invalid location. C // C program to demonstrate // an invalid memory access error #include <stdio.h> int a[5]; int main() { int s = a[-11]; printf("%d", s); return 0; } Output327462. Dividing by zeroWhen we are trying to divide any number by zero then we get this type of error called floating-point errors. C // C program to demonstrate // an error occurred by dividing 0 #include <stdio.h> int main() { int a = 5; printf("%d", a / 0); return 0; } Output: Error of dividing by zero3. Segmentation FaultsLet us consider an array of length 5 i.e. array[5], but during runtime, if we try to access 10 elements i.e array[10] then we get segmentation fault errors called runtime errors. Giving only an array length of 5 C // C program to demonstrate // an error of segmentation faults #include <stdio.h> int main() { int GFG[5]; GFG[10] = 10; return 0; } But in output trying to access more than 5 i.e if we try to access array[10] during runtime then we get an error Output: Segmentation Fault Error4. Large memory allocation/Large Static Memory Allocation : In general, all online judges allow up to 10^8. However, to be on the safe side, use up to 10^7 unless it is required. In the below example we have mentioned more than 10^8 so, it will cause an error due to large memory allocation. C // C program to demonstrate // an error of large memory allocation #include <stdio.h> int main() { int GFG[10000000000]; printf("%d", GFG); return 0; } Output: Large Memory Allocation Error5. Making common errors: The below code gives runtime error because we have declared a variable as long int but in scanf we have used %d instead of %ld. So it will give an error. C // C program to demonstrate // a common error #include <stdio.h> int main() { long int GFG; scanf("%d", &GFG); return 0; } Output: Common Error Comment More infoAdvertise with us Next Article C Program to Show Runtime Exceptions L laxmigangarajula03 Follow Improve Article Tags : C Programs C Language C Error Handling Programs Similar Reads C Program to Show Types of Errors Here we will see different types of errors using a C program. In any programming language errors are common. If we miss any syntax like parenthesis or semicolon then we get syntax errors. Apart from this we also get run time errors during the execution of code. There are 5 types of error in C: Synta 4 min read C Program to Show Unreachable Code Error Here, we will see how to show unreachable code errors using the C program. Unreachable statements are statements that will not be executed during the program execution. These statements may be unreachable due to the following reasons: Return statement before print statement.Infinite loop before stat 3 min read Using goto for Exception Handling in C Exceptions are runtime anomalies or abnormal conditions that a program encounters during its execution. C doesnât provide any specialized functionality for this purpose like other programming languages such as C++ or Java. However, In C, goto keyword is often used for the same purpose. The goto stat 4 min read Interesting Facts in C Programming | Set 2 Below are some more interesting facts about C programming: 1. Macros can have unbalanced braces: When we use #define for a constant, the preprocessor produces a C program where the defined constant is searched and matching tokens are replaced with the given expression. Example:C #include <stdio.h 2 min read Your First C Program Like in most of the programming languages, program to write the text "Hello, World!" is treated as the first program to learn in C. This step-by-step guide shows you how to create and run your first C program.Table of ContentSetting Up Your EnvironmentCreating a Source Code FileNavigating to the Sou 4 min read C Program to Handle Divide by Zero In C programming, there is no built-in exception handling like in other high-level languages such as C++, Java, or Python. However, you can still handle exceptions using error checking, function return values, or by using signal handlers.There are 2 methods to handle divide-by-zero exception mention 3 min read How to Detect Memory Leaks in C? In C, memory leaks occur when programmers allocate memory by using functions like malloc, calloc, realloc etc., but forget to deallocate the memory by using free function. In this article, we will learn how to detect memory leaks in C. Detecting Memory Leaks in C ProgramsDetecting memory leaks in C 3 min read C Programs To learn anything effectively, practicing and solving problems is essential. To help you master C programming, we have compiled over 100 C programming examples across various categories, including basic C programs, Fibonacci series, strings, arrays, base conversions, pattern printing, pointers, and 8 min read Error Handling During File Operations in C File operations are a common task in C programming, but they can encounter various errors that need to be handled gracefully. Proper error handling ensures that your program can handle unexpected situations, such as missing files or insufficient permissions, without crashing. In this article, we wil 5 min read GDB (Step by Step Introduction) GDB stands for GNU Project Debugger and is a powerful debugging tool for C (along with other languages like C++). It helps you to poke around inside your C programs while they are executing and also allows you to see what exactly happens when your program crashes. GDB operates on executable files wh 5 min read Like