c++ - Why functionss work perfectly good without return at the end -


i have question related function without return statement @ end of definition. how works? can return becouse value return allocated on stack random number when call func? check example below:

#include <iostream>  using namespace std;  int fun1(){     cout << "fun1" << endl; }  char fun2(){     cout << "fun2" << endl; }  short fun3(){     cout << "fun3" << endl; }  float fun4(){     cout << "fun4" << endl; }  double fun5(){     cout << "fun5" << endl; }  int main() {     cout << fun1() << " " << endl;    cout << fun2() << " " << endl;    cout << fun3() << " " << endl;    cout << fun4() << " " << endl;    cout << fun5() << " " << endl; } 

in order create function without return statements, need make "void" function. remember variable types used define function type of variable returned @ end of function. if function int type, expects integer in return. if function char type, expects character in return.

the above example won't work because in each case, compiler expecting return @ end of function. functions work if have "void int" before each function name, so.

void int fun1() {      cout << "fun1" << end; } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -