C
Chris Dollin
raghu said:But it happened in gcc compiler. I modified the code for number of
times and concluded in that manner.
So? /The behaviour is undefined/. An implementation can do what it
likes. "What it likes" is often whatever the natural consequence of
the implementation's choices are - ie, it doesn't check, it doesn't
care.
There's no point in just tinkering with a compiler and seeing
what happens. A different compiler could make different choices.
What's /likely/ to have happened is that `printf` returns a result
in some integer register, let's call it R0. The call to `b` doesn't
do anything (well, it might push and pull a return address), so
doesn't alter R0. Then when `b` returns, the value of R0 is assigned
to `x`.
A decent compiler will of course have warned about the implicit
int definition of `b` and that it doesn't have a `return` statement.
If you insist on tinkering with code, try adding:
int fiddleResult() { return 17; }
int b() { fiddleResult(); }
... main as before ...
I expect you'll now find that `x` gets `17` as its value.