In a C program, within the main function, is there a difference between
exit(1);
and
return 1;
?
In a C program, within the main function, is there a difference between
exit(1);
and
return 1;
?
exit represents immediate termination which will terminate program.
In the below program when we return value from main the destructors will be called but not in case when we use exit(value).
#include <iostream>
#include<string.h>
using namespace std;
class String {
private:
char* s;
int size;
public:
String(char*); // constructor
~String(); // destructor
};
String::String(char* c){
cout<<"Calling constructor"<<endl;
size = strlen(c);
s = new char[size + 1];
strcpy(s, c);
}
String::~String() {
cout<<"Calling destructor"<<endl;
delete[] s;
}
int main(){
String s("Hell o");
exit(1);
//return 1;
}