+ 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
3 Respuestas
+ 1
void not return value when used return void hope (int y) { return y ; } error
27th Jan 2017, 7:41 PM
ASNM
ASNM - avatar
+ 1
when you use a data type before a function, it basically says that the function will return a value, while void says that there wont be any values returned by the function and would give an error if you tried. For example: int function(){} //This will return an integer because of the int string function(){} //This will return an integer because of the string void function(){} //This wont return anything, think of void like nothing know what I mean? //This will give out an error: void function(int x) { return x; }
27th Jan 2017, 8:19 PM
Dawzy
Dawzy - avatar
+ 1
Thank you
27th Jan 2017, 11:02 PM
Mich
Mich - avatar