Output
Last instruction in main()
In func2
In func1
Solution
#include <iostream>
#include <stdlib.h>
using namespace std;
void func1()
{
cout << "In "<< __FUNCTION__ << endl;
}
void func2()
{
cout << "In "<< __FUNCTION__ << endl;
}
int main(int argc, char* argv[])
{
atexit(func1);
atexit(func2);
cout << "Last instruction in main()" << endl;
return 0;
}
Problem
C library provides functions like onexit(), atexit() to process the specified function at exit.