Sunday, March 14, 2010

56

In the following program which one will run without any errors?:






#define a 2
int main()
{
int b=2;
switch(b)
{
case a:
printf("%d",b);
break;
}
return 0;
}

int main()
{
int a=2,b=2;
switch(b)
{
case a:
printf("%d",b);
break;
}
return 0;
}


Answer


The first program.
we can use only constants in case.
in first program a is defined using #define so it's constant.
in second program a is defined using integer datatype(obviously it's variable not constant).

0 comments:

Post a Comment