abhy <abhijitkrao283@gmail.com> writes:
> On Oct 21, 4:00 pm, Srinu <sinu.nayak2...@gmail.com> wrote:
>> If we compile the below piece of code, it gets compiled. But gives
>> weird result.
>>
>> switch(x)
>> {
>> int y=2;
>>
>> case 1:
>> printf("%d", y);
>>
>> }
>>
>> What, if any, the C standard says about it?
>
> Can u tell me what weird results it gives ?
Please don't use silly abbreviations like "u" for "you". This isn't a
chat room. Take the time to spell out simple words.
Yes, showing the actual questionable output is almost always a good
idea. In this particular case, though, it's unnecessary. The
variable y is uninitialized when it's printed; any output is possible.
(Actually, the behavior is undefined, so in principle *anything* is
possible, but it will most likely print some arbitrary value of type
int.)
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"