Return statement

A return statement causes the program logic to return to the point in the program from which the function was accessed. The general from of a return statement is:

return expression;

This statement causes the value expression to be returned to the calling part of the program. Of course, the data type of expression should match the declared data type of the function. For a void function, which does not return any value, the appropriate return statement is simple:

Return;

A maximum of one expression can be included in a return statement. Thus, a function can return a maximum of one value to the calling part of the program. However, a function definition can include multiple return statements, each containing a different expression, which are conditionally executed, depending on the program logic.

Note that, by convention, the main function is of type int and returns the integer value 0 to the operating system, indicating the error – free termination of the program. In its simplest from, the main function possesses no arguments. The library function call exit (1) causes the execution of a program to abort, returning the integer value 1 to the operating system, which (by convention) indicates that the program terminated with an error status.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext