r/AskProgramming • u/Fun-Ship-2026 • Jun 05 '26
Help beginner
What is difference between output and return. I have seen some videos and it says like return is for computer and output is for human. Is it like two seperate ways one is displayed and one is stored? If so then wouldn't it become same like a stored variable?
1
Upvotes
2
u/AFK_MIA Jun 05 '26
You're mostly correct, but I think it is helpful to think about the terminal as an output device - so printing to terminal is similar to printing to an actual printer (which historically that's what the terminal was) or saving to a file. Because of this, printing to terminal (output) is sending whatever information you put in the print statement to something outside of your running program (i.e. the human) whereas having a function return a value keeps that inside the running program.
2
u/soundman32 Jun 05 '26
They are different words for the same thing. Some languages have a return statement, and some have an output statement. A method does something and when complete, that result is sent back to the caller.
The format of the result is probably a better differentiator. Text output
Hello Johnis aimed at humans (and computers can find it difficult to parse), whereas json{ "greeting":"hello", "name":"john"}is aimed at computers (but readable by humans). Binary formats are even more targeted at computers, and can require a lot of work for a human to parse what they mean.2
u/KingofGamesYami Jun 05 '26
The terms 'output' and 'return' are heavily overloaded. They are used in many different contexts to refer to slightly difference concepts.
The most generic use, at least within a programming languages, is to refer to the standard output stream as output and a function return value as return.
The standard output stream is a defined interface between a program and whatever started the program. Historically terminals would display any values written to it directly to the user. In modern computing, we often use a terminal emulator to run programs which has the same behavior.
Another common option is redirecting the standard output stream to a text file. This provides persistent context of what a program did, which can be useful for monitoring a long running background task.
A function return value is a single value that is provided to the function's callee after execution. This is often useful to indicate success/failure of the operation, or to provide some result that is then used for further processing. The constraints on how exactly they work vary depending on programming language, as functions typically do not cross language boundaries like the standard output does.
1
u/Responsible-Cold-627 Jun 05 '26
Output is a generic term for any output. Return is a keyword that returns a result from a function.
1
u/Kindly-Department206 Jun 05 '26
"Return" is used to instruct the computer on how to behave at the end of a function call. It's rare for this term to mean anything else.
"Output" is slightly ambiguous. It could sometimes be used as a synonym for "return."
"Output" could also mean "display to the human for information purposes". This is not at all related to "return."
It is definitely not helpful for novices for important terms to be ambiguous in this way.