Can we Return the value from the user defined function to main function without specifying with keyword? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we Return the value from the user defined function to main function without specifying with keyword?

In the code below,the fuction sum is returning the value of variable 's' to the main function without specifying.How and Why? https://code.sololearn.com/c7u1UiZHUVDJ/?ref=app

7th Feb 2019, 2:00 PM
Nitin Madas
Nitin Madas - avatar
1 Answer
+ 3
Not using return is undefined behaviour, it might even crash your program. The only exception where you don't need return is inside the main function, the compiler adds return 0 on its own if you don't. The value that just happens to be stored in the eax register of the cpu is the value that is returned, this may be the correct result, it may be some completely other variable or just garbage, it just depends on how the compiler decides to compile it. So don't forget the return statement.
7th Feb 2019, 3:27 PM
Dennis
Dennis - avatar