Questions about Booleans and return 0;

First of all I’m still loving the videos and everything is perfectly working out until now. Just have a few questions:

  • I thought in the beginning we learned that return 0; means everything is okay and we move on. But now we commented behind it; //exits the application. So what does return 0; actually do now?

  • For using the Boolean we needed to change the name from PlayAgain to bPlayAgain. Is that b really needed or just to make clear it is a boolean? Because we already have the; bool bPlayAgain = false; that is stating it is a boolean we ask for right?

Thank you to anyone that can answer these as simple as possible :slight_smile:

1 Like

The return 0; at the end of main basically just lets you know that the application completed. If you exit the program and don’t get a return value of 0, then you know something is wrong.

The naming convention of adding a b to the front of a boolean name is simply to conform to the UE4 standard. It is not necessary, but does seem handy, because if you look through your variables, all of your booleans are grouped together. I suppose that NOT using variable names that start with b that aren’t booleans is probably also a good idea. I think the idea looks more toward when the program is going to be much more complicated and the variable usage may not be near its declaration. Because of that, what it is may not be so clear by sight, but if you put a b in front of it, you know its a bool no matter what.

1 Like

Thanks Lucid_Stew for the simple answer!

Okay, in my train of thought the return 0; is a must to exit the application? So you always should put it at the end of the main then. But when I remove the return 0; at the end of main it still says “Press any key to continue” and stops the console successfully. I know I am probably a pain in the ass but I really wanna understand the basics well before moving on.

Maybe you just mean it is a return signal (we don’t visually read back) that tells us the total of actions are succesfully executed and we are finished? But it is not needed to actually stop/close the application?

If you don’t explicitly type return 0;, the program will default to return 0; if it terminates successfully. The program will close if the end of main is reached, but the information passed to the OS can vary depending on the state of the program on close. It’s not necessary for it to be there, but it is standard form and expected to be there. Omitting it saves nothing.

1 Like

Privacy & Terms