+ 3

What's the difference between printing the value and returning it ?

Print or return

25th Jul 2019, 7:28 PM
The unknown 321
The unknown 321 - avatar
7 Answers
+ 5
When you use print actually you force the function to print the output always. But do you want to print always? No! Sometimes you want to use it in another procedure so you should use return instead of print to it be usable for different occasions.
25th Jul 2019, 7:37 PM
Ali Shekari
Ali Shekari - avatar
+ 4
print: takes what is inside the () and prints it in the console, the value can't be taken from there. => only for testing / giving output return: only present inside a function. returns the content of a variable or a constant value, which can be used outside the function. => without it more than half of all functions wouldn't work/had no use totally diffrent! , but a value that is returned by a function can be printed too => make all functions return a value and then print it for testing purposes or for the actual output
25th Jul 2019, 8:01 PM
Anton Böhler
Anton Böhler - avatar
+ 3
returning returns a value to where the function was called. Printing is a basic way to display data to user.
25th Jul 2019, 9:00 PM
Seb TheS
Seb TheS - avatar
25th Jul 2019, 8:39 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Can you give code example please ? Try to make the code the same way you explained it. C++.
25th Jul 2019, 8:21 PM
The unknown 321
The unknown 321 - avatar
+ 1
The unknown 321 when you use return the value you get can be modyfied and used in multiple was, printing will just output it so the user can get info ...
26th Jul 2019, 2:16 PM
Anton Böhler
Anton Böhler - avatar