-3

Why I get the following output "-858993460" when using the following code:

#include<stdio.h>

int aNumber(void);

int main()
{   
    printf("%d", aNumber());    
    return 0;   
}

int aNumber(void) {
    int x = 1;
}

I am just curious. I know I need to use "return" to get the actual int 1 on my "printf"

gnimm
  • 17
  • 4
  • Possible duplicate of [When and why will an OS initialise memory to 0xCD, 0xDD, etc. on malloc/free/new/delete?](https://stackoverflow.com/questions/370195/when-and-why-will-an-os-initialise-memory-to-0xcd-0xdd-etc-on-malloc-free-new) – phuclv Aug 18 '18 at 11:07

1 Answers1

2

Because the return value of aNumber is undefined. Since you don't return a value, undefined behavior ensues. Don't count on it. On many machines EAX stores the return value. If you don't have a value for EAX, the previous value for it is used.

lost_in_the_source
  • 10,998
  • 9
  • 46
  • 75