# The return Statement

You can use the return statement to end the execution of a function and return program control to the function that called it. Here is the general form of the return statement

`return return-value;`

return-value is an optional expression to return.

If the function's return type is void, then it is invalid to return an expression. You can, however, use the return statement without a return value.&#x20;

If the function's return type is not the same as the type of return-value, and automatic type conversion cannot be performed, then returning return-value is invalid.&#x20;

If the function's return type is not void and no return value is specified, then the return statement is valid unless the function is called in a context that requires a return value. For example

```
x = cosine(y); 
```

In that case, the function cosine was called in a context that required a return value, so the value could be assigned to x.&#x20;

Even in contexts where a return value is not required, it is a bad idea for a non-void function to omit the return value.&#x20;

Here are some examples of using the return statement, in both a void and non-void function:

```
void print_plus_five(int x) {
  message(x + 5);
  return;
};
```

```
int square_value(int x) {
  return x * x;
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://muradkarakas.gitbook.io/sodium_documentation/language-reference/lexical-elements/statements/the-return-statement.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
