Returning Values from Functions

Returning Values from Functions

Functions may also return value along with the control, back to the caller. Such functions are called as returning functions.

Syntax

return_type function_name(){
  //statements 
  return type
}
  • The return_type can be any valid data_type.
  • the return statement is optional. Do not specify the retun null.
  • The data type of the value returned must match the return type of the function.
  • a function can return at the most one value. In other words, ther can be only one return statement per function.

Example

void main(){
  print(work);
}
String work(){
  //function definition
  return "I am working.";
}

It will produce the following output:-

I am working.