exit function

The C++ library function exit terminates the program immediately. Any open file descriptors belonging to the process and children processes are closed. exit function does not return any value.
C++ लाइब्रेरी में उपस्थित एग्जिट फंक्शन के द्वारा प्रोग्राम को तत्काल समाप्त कर दिया जाता है, प्रोग्राम से सम्बंधित सभी फ़ाइल एवं चाइल्ड प्रोसेसेज को बंद कर दिया जाता है। एग्जिट फंक्शन कोई वैल्यू लौटाता नहीं  है।

Syntax:-
void exit(int status);

here status is the status value returned to the parent process.
यहाँ स्टेटस वैल्यू पैरेंट प्रोसेस को रिटर्न की जाती है। 

Example
C++ program to show the use of exit() :-
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
void main(){
int n;
clrscr();
cout<<"Enter a Positive Integer  Number"<<endl;
cin>>n;
if(n<=0){
cout<<"wrong input"<<endl;
getch();
exit(0);
}
cout<<"Square Root of " <<n<<" = "<<sqrt(n)<<endl;
getch();
}

No comments:

Post a Comment