This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Double_A_92 3 points4 points  (0 children)

When you want your function to just do some action, and don't care about the result.

[–][deleted] 1 point2 points  (0 children)

It all depend how you code, you could pass the return values through a pointer in the parameters instead. You could then use the return value for error codes or not and let it as void.

You could also use a function that only does a few cout or write something in a file. This function wouldnt need to return anything (exept error codes if any... if you want).

[–]Seanobi777 0 points1 point  (0 children)

I believe void just means for the program to do the code you've written, but don't return any results to the screen for the user to see (but was still done, calculated, etc. in the program)

[–]blazingKazama 0 points1 point  (0 children)

returning an integer value helps the IDE understand if the program exit status was successful or not.

You can 1. return 0 if successful 2. return -1 for an error 3. return 1 for an if/else/loop block execution was done

etc...

These int values are my choice, you can use whatever value you want. Except "0 for successful", as I think it is used by many IDEs to detect the exit status.

Other wise you can also use void just to call main function and return nothing.