+ 1

difference and usages for void and integer functions?

examples of uses for Void functions? examples of uses for int functions? why my void function prints a value to the screen? I thought a void function isn't supposed to return a value. #include <iostream> using namespace std; void hope (int y) { cout<< y; } int main () { hope(89); return 0; }

27th Jan 2017, 7:28 PM
Mich
Mich - avatar
2 Answers
+ 3
Printing and returning values are different processes. Printing displays to the screen while returning gives the value back to whatever called the method. int func() { return 5; } int a = func(); a now has the value of 5 which the func() method returned.
28th Jan 2017, 7:08 AM
Jafca
Jafca - avatar
+ 2
Thank you Jafca, that clarifies
29th Jan 2017, 10:48 PM
Mich
Mich - avatar