Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What will happen if set the return value to 17 rather than 1 or 0 ??Kindly guide me...


What I have tried:

What will happen if set the return value to 17 rather than 1 or 0 ??Kindly guide me...
Posted
Updated 20-Feb-18 20:35pm
Comments
Suvendu Shekhar Giri 21-Feb-18 2:30am    
--There is no language called c+, it's either c or c++
--you haven't showed the code / function which returns the value

**You can return 17 if the return type of the function is int
CPallini 21-Feb-18 3:16am    
Return 42, instead.

Nothing!

Every function may return any value. The difference is with main function.

Quote:
When main returns zero (either implicitly or explicitly), it is interpreted by the environment as that the program ended successfully. Other values may be returned by main, and some environments give access to that value to the caller in some way, although this behavior is not required nor necessarily portable between platforms. The values for main that are guaranteed to be interpreted in the same way on all platforms...


See:
Functions - C++ Tutorials[^]
Main function - cppreference.com[^]
 
Share this answer
 
Depends on what the return value type is and what - exactly - the method is supposed to do.
In C and C++, any non-zero value is effectively "true" and zero alone represents "false".
So if you function return value is being used in a conditional:
C++
if (MyFunctiuon())
   {
   ...
Then returning seventeen (or one hundred and eighty) instead of one will make no difference.

If the function do in the return is the main function, then yes, it will - 0 indicates "no error, normal termination" while any other value is an error code (which can be translated to an error message to explain why it's a problem).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900