Is there a default return value for C ++ functions?

I am surprised that the file containing the following lines of code was successfully compiled, and the linker creates the executable. I thought that all functions except mainshould have a valid operator returnif the return type is not equal void.

int foo(){}
double bar(){}
int main(){}

What am I missing?

+4
source share
2 answers

I thought that all functions except mainshould have a valid return statement if return type void.

Yes they should. You will get undefined behavior if they don't.

What am I missing?

, , ; .

, .

+2

, , undefined. , , .

, .

+8

Source: https://habr.com/ru/post/1530491/


All Articles