Srinu 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?
What you fail to realize is that initialization of an automatic
variable requires the generation of code. That code has to go
where the "int y = 2;" statement appears. There is no reason for
the switch statement to transfer control to that code, so y is
uninitialized (or worse) when the printf is executed.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from
http://www.teranews.com