C Program to Show Runtime Exceptions Last Updated : 03 Aug, 2022 Summarize Comments Improve Suggest changes Share 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 Programming Language Tutorial C is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used 5 min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi 6 min read What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac 13 min read Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i 6 min read Like