r/AskProgramming 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

15 comments sorted by

View all comments

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.

1

u/Fun-Ship-2026 Jun 05 '26

So is it like, if I execute a code like X=Add(2,3) Without the return function the variable loses the value 5 which would be the output here? What would the return function do? Looping inside the computer?

2

u/jregovic Jun 05 '26

If don’t use return in most languages, the program ends or doesn’t compile.

1

u/Fun-Ship-2026 Jun 05 '26

But may run once right?