This function causes the program to terminate from any portion of the program and does not have any return value. It has only one argument whose value is returned to the operating system when the program is terminated. This function is included in the <stdlib.h> header file. Hence this header file must be included in the beginning of the program.
Example
To find whether a given number is prime or not using do ..while loop.
#include<iostream.h> #include<math.h> #include<stdlib.h> #include<conio.h> void main() { int n; int q; clrscr(); cout<<"Enter the Number : "; cin>>n; int i=2; do { if(n%i==0) goto II; i++; } while(i<=int( sqrt(n))); cout<<n<<" is a prime number "; exit(1); II: cout<<"Not a prime number "<<"\n"; getch(); }