R
Rahul
Hi,
Is the following correct? Here i have declaread a char array in case 1:
and am using the same in case 2:
first I tried another definition of ch in case 2: assuming that if i=2
then char ch[] will not get allocated in case 1:. But the compiler gave
me (re-definition error) so i removed it and now its working fine.
Is it correct as per the standard?
switch (i)
{
case 1:
char ch[12];
strcpy(ch, "case 1\n");
cout<<ch;
break;
case 2:
strcpy(ch, "case 2\n"); //Can i use it here, when i=2, why
should the compiler allocate
// the variable shich is
declared in the case which is not true.
cout<<ch;
break;
default:
strcpy(ch, "default\n"); // Is it ok here also?
cout<<ch;
}
Is the following correct? Here i have declaread a char array in case 1:
and am using the same in case 2:
first I tried another definition of ch in case 2: assuming that if i=2
then char ch[] will not get allocated in case 1:. But the compiler gave
me (re-definition error) so i removed it and now its working fine.
Is it correct as per the standard?
switch (i)
{
case 1:
char ch[12];
strcpy(ch, "case 1\n");
cout<<ch;
break;
case 2:
strcpy(ch, "case 2\n"); //Can i use it here, when i=2, why
should the compiler allocate
// the variable shich is
declared in the case which is not true.
cout<<ch;
break;
default:
strcpy(ch, "default\n"); // Is it ok here also?
cout<<ch;
}