Why this is giving random answers each time i run this.

In general, the third-local-int in a function has got to be random - it could previously have been an int, or the bottom byte of one int and the top n-1 bytes of another (depending on the architecture's alignment rules), or part of a double, a pointer, a char array, a union with bit fields, part of a cat gif, ...

Knowing more about the when the program calls a function could tell you more about possible contents of the uninitialised memory - although you couldn't look at eg printf source and guess what might be on the stack.

This particular variable in main is a bit less random; the os has probably recently zeroed the pages of the stack segment before giving it to the process, and a look at what the c library does just before it calls main might narrow the possibilities down a bit.

/r/C_Programming Thread