The exit() function in C17 Mar 2025 | 4 min read The exit() function is used to terminate a process or function calling immediately in the program. It means any open file or function belonging to the process is closed immediately as the exit() function occurred in the program. The exit() function is the standard library function of the C, which is defined in the stdlib.h header file. So, we can say it is the function that forcefully terminates the current program and transfers the control to the operating system to exit the program. The exit(0) function determines the program terminates without any error message, and then the exit(1) function determines the program forcefully terminates the execution process. ![]() Important points of the exit() functionFollowing are the main points of the exit function in C programming as follows:
Syntax of the exit() function The exit() function has no return type. int status: It represents the status value of the exit function returned to the parent process. Example 1: Program to use the exit() function in the for loop Let's create a program to demonstrate the exit (0) function for normal terminating the process in the C programming language. Output Enter the last number: 10 Number is 1 Number is 2 Number is 3 Number is 4 Number is 5 There are two types of exit status in CFollowing are the types of the exit function in the C programming language, as follows:
EXIT_SUCCESS: The EXIT_ SUCCESS is the exit() function type, which is represented by the exit(0) statement. Where the '0' represents the successful termination of the program without any error, or programming failure occurs during the program's execution. Syntax of the EXIT SUCCESS Example 1: Program to demonstrate the usage of the EXIT_SUCCESS or exit(0) function Let's create a simple program to demonstrate the working of the exit(0) function in C programming. Output Start the execution of the program. Exit from the program. Example 2: Program to use the EXIT_SUCCESS macro in the exit() function Let's create a C program to validate the whether the character is presents or not. Output Enter the character: Y Great, you did it. EXIT_FAILURE: The EXIT_FAILURE is the macro of the exit() function to abnormally execute and terminate the program. The EXIT_FAILURE is also represented as the exit(1) function. Whether the '1' represents the abnormally terminates the program and transfer the control to the operating system. Syntax of the EXIT_FAILURE Example 1: Let's create a program to use the EXIT_FAILURE or exit(1) function Output Enter the num1: 20 Enter the num2: 6 20 / 6 : 3.333333 2nd Run Enter the num1: 20 Enter the num2: 6 Dividend cannot be zero Example 2: Let's create another program to use the EXIT_FAILURE to terminate the C program. Output Unable to open the defined file. Next TopicConst Qualifier in C |
In this article, we will discuss the C program to search for an element in an Array with their different ways and examples. What is an Array? A data structure called an array holds a fixed-length series of identical-type items. It is frequently used to store and manipulate...
3 min read
In C, decision-making statements are technology structures enabling programmers to make decisions based on specific conditions or criteria. In C, there are three primary decision-making statements that you can use: If-else statements Switch statements Conditional operator statements Each of these statements allows you to make decisions in different ways, depending...
4 min read
Billing software is used to invoice clients for services and goods as well as to track time and billing. It helps with the administration of a chain of stores as well as other company billing systems. Additionally, it provides recurring services and a professional rent billing...
23 min read
As we know natural numbers contain all the positive numbers starting from 1, 2, 3, to n numbers or infinity. For example, suppose when we calculate the sum of the first 25 numbers. That means we start adding the numbers from 1 to the given number...
5 min read
In this article, we learn some of the old concepts that were usually used and implemented in the 16 bit Intel architectures in the earlier days of Ms-Dos, but they are not used much nowadays. Still, these concepts are very important because they are like the...
4 min read
This software counts the number of times a substring appears in a string after receiving a string and a substring as input. Let us look at an example: Solution would be: Take as input a string and a substring. Look first in the string for the substring. Count the...
4 min read
In this article, you will learn about the difference between Object and Source code. But before discussing the differences, you must know about Object and Source code. What is Object Code? Object code is code that computers and other devices can understand. It is generated from a program's...
5 min read
The Calendar in C Programming is a Calendar Project In C that helps you find the date and day you need by being built in the C programming language. It also does a few other tasks. A C-written calendar application may offer information going back...
24 min read
Finding pieces within a collection is a typical task in the world of programming. The linear search is one of the most elementary and basic search methods. The specifics of the linear search will be covered in this blog post, along with its implementation in...
3 min read
Pointers are a fundamental concept in programming languages that allow for efficient memory management and direct access to memory locations. Pointers are variables that store the memory address of another variable, rather than its value. This allows for various operations to be performed on the memory...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India