Fiveable
Fiveable

Return Statement

Definition

A return statement is used in a function to specify the value that should be returned when the function is called. It allows the function to send a value back to the code that called it.

Analogy

Think of a return statement like ordering food at a restaurant. When you place an order, you expect to receive something in return, such as your meal or a receipt. Similarly, when a function uses a return statement, it "orders" or specifies what value should be sent back to the code that called it.

Related terms

Function: A function is a block of code that performs a specific task and can be reused throughout the program. It may use return statements to send values back to the calling code.

Parameter: A parameter is a variable defined in a function's declaration. It represents an input value that can be passed into the function when it is called.

Void: Void is used as the return type for functions that do not need to send any value back. These functions typically perform actions rather than returning data.



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.