0
#include<iostream>

using namespace std;

int printMe(int a)
{
        a=a*a;
}

int main()
{
        int capture;
        capture=printMe(5);
        cout<<capture;
        return 0;
}

How am i getting 25 as value printed without the return value from printMe function?? can anyone Please explain if anything missed

Azeez
  • 25
  • 5
  • 1
    Undefined behavior. – πάντα ῥεῖ Mar 01 '17 at 10:21
  • 1
    http://stackoverflow.com/questions/2784075/is-a-return-statement-mandatory-for-c-functions-that-do-not-return-void – Andrew Kashpur Mar 01 '17 at 10:21
  • I think an implicit return is still undefined behavior in the standard, so it might depend on your compiler. why would you even do that? – xander Mar 01 '17 at 10:23
  • 1
    One explanation for *seems to work* is that the result of the multiplication ends up somewhere, like in a register. It just could happen that it is the same register that would be used in the missing `return a;`. – Bo Persson Mar 01 '17 at 11:01

0 Answers0