
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What is exit() function in C language?
The exit () function is used to break out of a loop. This function causes an immediate termination of the entire program done by the operation system.
The general form of the exit() function is as follows −
void exit (int code);
The value of the code is returned to the calling process, which is done by an operation system. Generally, zero is used as return code to indicate normal program termination.
Example
Following is the C program for use of exit() function −
#include<stdio.h> void main(){ char ch; printf("B: Breakfast"); printf("L: Lunch"); printf("D: Dinner"); printf("E: Exit"); printf("Enter your choice:"); do{ ch = getchar(); switch (ch){ case 'B' : printf ("time for breakfast"); break; case 'L' : printf ("time for lunch"); break; case 'D' : printf ("time for dinner"); break; case 'E' : exit(0); /* return to operating system */ } } while (ch != 'B' && ch != 'L' && ch != 'D'); return 0; }
Output
When the above program is executed, it produces the following result −
B: Breakfast L: Lunch D: Dinner E: Exit Enter your choice:D Time for dinner
- Related Articles
- What is strlen function in C language?
- What is strcoll() Function in C language?
- What is strspn() Function in C language?
- What is strcpy() Function in C language?
- What is strcat() Function in C language?
- What is strncat() Function in C language?
- What is strcmp() Function in C language?
- What is strncmp() Function in C language?
- What is strstr() Function in C language?
- What is strncpy() Function in C language?
- What is strrev() Function in C language?
- What is function prototype in C language
- What is strtok() function in C language?
- What is strtok_r() function in C language?
- What is a malloc function in C language?

Advertisements