
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Exit vs Exit Function in C and C++
In this section we will see what are the differences between exit() and _Exit() in C and C++. In C the exit() terminates the calling process without executing the remaining code which is present after exit() function.
In C++11, one new function is present called _Exit(). So what is the feature of this function? The exit() function performs some cleaning before terminating the program. It clears the connection termination, buffer flushes etc. This _Exit() function does not clean anything. If we test using atexit() method, it will not work.
Let us see two examples where at first we are using exit() function, then in the next
Example
#include<bits/stdc++.h> using namespace std; void my_function(void) { cout << "Exiting from program"; } int main() { atexit(my_function); exit(10); }
Output
Exiting from program
Example
#include<bits/stdc++.h> using namespace std; void my_function(void) { cout << "Exiting from program"; } int main() { atexit(my_function); _Exit(10); }
Output
In this case the output is blank. Nothing has come.
Advertisements