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 |
What is an octal number system? An octal number system is a number system which is having base-8 where base-8 represents the eight digits from 0 to 7. What is a Hexadecimal number system? A hexadecimal number system is a number system which is having base-16 where base-16 represents...
5 min read
In this topic, we will learn about GCD and find out different ways to get programming languages. The GCD is a mathematical term for the Greatest Common Divisor of two or more numbers. It is the Greatest common divisor that completely divides two or more...
6 min read
This section will discuss the conversion of Binary numbers to Decimal numbers. Before going to the concept, we need to understand Binary numbers and decimal numbers. As we know, the computer does not understand the words or numbers that humans write or do. Instead, it only...
5 min read
We will learn about the extremely helpful conio.h header file in C in this essay. We will also examine the functions contained in conio.h as well as the usage of conio.h in the C programming language. What in C programming is conio.h? The most common type of header...
6 min read
Loops are part of almost every complex problem. Too many loops/ nested loops increase the required time, thus increasing the time complexity of the program. The window sliding technique is one of the computation techniques used to reduce the number of nested loops used in a...
4 min read
In this section, we will learn the getchar() function in the C programming language. A getchar() function is a non-standard function whose meaning is already defined in the stdin.h header file to accept a single input from the user. In other words, it is the C...
3 min read
Introduction Tokens fundamentally influence programming language syntax and organization. Tokens, which represent distinct meanings in the C programming language, are the fundamental components of code construction. They contain preprocessor directives, keywords, identifiers, constants, operators, and punctuation marks. We will explore the varieties of C tokens in this...
4 min read
Description of memcmp() The memcmp() function allows the user to make a comparison between the bytes of the two mentioned characters. Depending upon the result after the comparison, it can return a positive or negative integer value. The function can also return 0. The function is represented as...
6 min read
In this article, we are going to discuss the atoi() function in c with their examples. What is Atoi()? The atoi() function converts an integer value from a string of characters. The input string is a character string that may be turned into a return type numeric value....
4 min read
Unsigned int is a data type in the C programming language that stores non-negative integer values. It is similar to the "int" data type, but unlike "int", it does not allow for the storage of negative numbers. This article will explore C's unsigned int data type,...
12 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