When an object is created in your main() function, is its destructor called upon program termination? I would assume so since main() still has a scope( the entire program ), but I just wanted to make sure.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on how your program terminates. If it terminates by having main return (either by an explicit return or falling off the end), then yes, any automatic objects in main will be destructed.
But if your program terminates by calling exit(), then main doesn’t actually go out of scope and any automatic objects will not be destructed.