exit() फंक्शन का उपयोग लूप से बाहर निकलने के लिए किया जाता है। यह फंक्शन ऑपरेटिंग सिस्टम द्वारा पूरे प्रोग्राम को तत्काल समाप्त कर देता है।
सिंटैक्स
void exit(int code);
कोड का मान कॉलिंग प्रोसेस को वापस किया जाता है, जो ऑपरेटिंग सिस्टम द्वारा किया जाता है। आमतौर पर, सामान्य प्रोग्राम समाप्ति को इंगित करने के लिए जीरो (0) को रिटर्न कोड के रूप में उपयोग किया जाता है।
उदाहरण
निम्नलिखित C प्रोग्राम exit() फंक्शन के उपयोग को दर्शाता है:
#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); /* ऑपरेटिंग सिस्टम पर वापस लौटें */
}
} while (ch != 'B' && ch != 'L' && ch != 'D');
return 0;
}
आउटपुट
B: Breakfast L: Lunch D: Dinner E: Exit Enter your choice:D Time for dinner