What is the Difference Between return 0 and exit(0) in a C++ Program



In a C++ program, the main function often returns a value to the operating system. Usually this is accomplished by using the return keyword. However, we can also return a value by using the exit keyword. This video explains the difference between leaving a main function with return vs exit.

This channel, Paul Programming, provides helpful computer science tutorials with an emphasis on C++ and data structures. Paul is a professional software engineer and tutor who has a knack for explaining complex concepts in a simple and easy to understand way.

Please subscribe to this channel to benefit from the latest channel updates.

If you are looking for a good reference book on C++ please consider the following book recommendation.

If you would like to help support Paul in a more direct way, consider donating at the following link –

Thank you for watching! The success of this channel would never be possible without people like you! Thank you for your support!

STILL NEED MORE HELP?
Connect one-on-one with a Programming Tutor. Click the link below:

🙂

Nguồn: https://newblurayrelease.com/

Xem thêm bài viết khác: https://newblurayrelease.com/lap-trinh-php/

  • Pls what compiler are you using in this video?

    Bassey Godwin July 29, 2020 10:03 pm Reply
  • exit is not a keyword, it is a function.

    Simon Mărăcine July 29, 2020 10:03 pm Reply
  • What application are you using??

    Blaze071234 July 29, 2020 10:03 pm Reply
  • Could you have done the same a "for " of "while " loop intered of the "do" loop.

    Iva Emply July 29, 2020 10:03 pm Reply
  • if main prgm return 0 means prgm run success (true) if main return 1 or retrun -1 means ???

    Selva Priya July 29, 2020 10:03 pm Reply
  • What is the difference between return 0 and return 1 in main function ?

    Selva Priya July 29, 2020 10:03 pm Reply
  • you cant use return outside the main function to exit the programm.

    xCwieCHRISx July 29, 2020 10:03 pm Reply
  • Thank you so much for this video, i could not get my if statement to stop running in my function!!!

    Mouse July 29, 2020 10:03 pm Reply
  • 9:25 "The main difference between the two is when we use the return keyword, the deconstructor of our objects are called whereas if we just use the exit keyword we just simply exit the program without calling any deconstructor for our objects".

    Daniel The Kiing July 29, 2020 10:03 pm Reply
  • Sir i understood the difference between exit and return .but why to use return or exit?

    fake fake July 29, 2020 10:03 pm Reply
  • YOU LEARN SOMETHING MORE EVERYDAY:DDDDDDDDDDDDD

    A. N. July 29, 2020 10:03 pm Reply
  • just delete the damn system 32

    Rafael Dasigni July 29, 2020 10:03 pm Reply
  • Are there any videos where I can see "return 0" used for the purpose of telling whether a function worked successfully or not? I've seen that explanation given many times for why "return 0" is used, but I'd like to actually see an application where that turns out to be useful.

    sicktoaster July 29, 2020 10:03 pm Reply
  • It is possible to compare strings using == and !=. To me this less confusing compared to using the compare function.
    while (choice != "exit" && choice != "return");

    Peterolen July 29, 2020 10:03 pm Reply
  • +Paul Programming
    Hey just wanted to ASK if you are still going to make vids?

    pascal erkens July 29, 2020 10:03 pm Reply
  • sublime <3 <3 <3

    Dhruvo DZ July 29, 2020 10:03 pm Reply
  • +Paul Programming

    Your Channel is so super for learing very interesting c++ stuff. Thx for your super helpful and very well explained videos.

    pascal erkens July 29, 2020 10:03 pm Reply
  • your videos deserve much more attention

    Adam Djellouli July 29, 2020 10:03 pm Reply
  • Destructors can do more than just deallocating memory. If you have a HighScoreList class you might want to save the highscores to a file when the destructor runs. If your program is a networked game some constructor might want to send information to let the other computers know you are disconnecting.

    Peterolen July 29, 2020 10:03 pm Reply
  • Why the video is called "… in a C or C++ Program" but the difference is shown using classes, which are only in C++? Is there any difference in C?

    Gregory Borodin July 29, 2020 10:03 pm Reply
  • thank you so much for this!
    i wanted to ask. will the memory of the object be deleted if exit is use or will it be there in the memory until deleted by an external source?

    Neel Shukla July 29, 2020 10:03 pm Reply
  • Would an operating system also deallocate dynamically allocated memory?

    Shadow4707 July 29, 2020 10:03 pm Reply
  • Thank you so much for clearing this up. It's something that I've always wanted to know!

    Karan Rajpal July 29, 2020 10:03 pm Reply

Leave a Reply

Your email address will not be published. Required fields are marked *