C++ Factorial Calculator Exercise Solution

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
30 replies · 8K views
estro said:
You main function looks like this: int main (void), it means that your function must return an integer. [you can change it to void main (void), then you will not need any return...]


Actually, main implicitly returns 0 for C++, so (for the main function only) you may omit "return 0;"

void main(void) is not okay!

It is not what is specified by the standards.

The caller is expecting a return value, and that value should be 0 for success.

It could result in stack corruption.
 
Last edited: