0

what is the difference between return and print function?

how to use the value stored in return function?

28th Nov 2017, 8:20 AM
Hasim Navsariwala
Hasim Navsariwala - avatar
2 Answers
+ 2
return is when you want something, like data or a value, out of a method. void methods don't return anything, but can certainly DO stuff (like print to the console or manipulate data). Think of the difference between withdrawing cash from an ATM vs checking your balance. In the first case our withdraw() function returns an int of money, or perhaps a Currency object. The checkBalance() method has a void return type, but it prints stuff to the screen
28th Nov 2017, 8:22 AM
Dan Walker
Dan Walker - avatar
+ 1
an extra reference for the above answer https://stackoverflow.com/a/750148/7887883
28th Nov 2017, 9:05 AM
Pavan Kumar T S
Pavan Kumar T S - avatar