Monday, 25 April 2016

what function will return when function with no return statement and return value is specified for function?

 
As per the standard result is undefined. On x86 architecture it will return the value of the EAX register.
EAX register will contain the result of the last executed instruction. Answer depends upon the platform which you were using.
But mostly it returns the result of the last executed instruction


#include<iostream>

int express()
{
   int a=5+5;
}

int donothing()
{

}

int declarevariable()
{
   int a=9;
}


int main()
{
   using namespace std;

   cout << '\n' << express();
   cout << '\n' << donothing();
   cout << '\n' << declarevariable();

   return 0;
} OUTPUT: 10 UNPREDICTABLE 9