#include
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}

Answers were Sorted based on User's Feedback



#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); ..

Answer / surenda pal singh chouhan

Compiler Error: Constant expression required in function
main.

Explanation:
The case statement can have only constant expressions (this
implies that we cannot use variable names directly so an
error).
Note:
Enumerated types can be used in case statements.

Is This Answer Correct ?    10 Yes 2 No

#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); ..

Answer / subha raman

yeah..itz mainly syntax error..
there shud not be any declaration of variables..in
case "j"..it must be "case 2"only..

Is This Answer Correct ?    6 Yes 1 No

#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); ..

Answer / pravin

if we use the single qutoes' 'at 1 and j the rest of
program is right because we already decleared the value of i
and i=1 .
so output should be "GOOD" only. (without" ")

Is This Answer Correct ?    3 Yes 1 No

#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); ..

Answer / moolshankershukla

#include
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
given above program is wrong only we can one changes and
will be run .

correct program is:

#include
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case 2: printf("BAD");
break;
}
}

Is This Answer Correct ?    2 Yes 0 No

#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); ..

Answer / suresh reddy

Compiler Error: Constant expression required in function
main

instead of using j u we can use case 'j' .

this is correct answer

Is This Answer Correct ?    5 Yes 5 No

#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); ..

Answer / shruti

nopes we cannot use 'j'... because single qutoes ' ' are
used only for character value.. i.e if it was
char i
switch(i)
then we cud have used it like that..


hence in our case,
it will give a compiler error...

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More C Interview Questions

Can you please explain the difference between strcpy() and memcpy() function?

0 Answers  


What is FIFO?

0 Answers  


Add Two Numbers Without Using the Addition Operator

0 Answers  


What’s the special use of UNIONS?

0 Answers   ADP,


? ???Mirror Mirror on the wall????????

1 Answers   channel V, DPI,






What is the difference between GETS();AND SCANF();

4 Answers   TCS,


What is the difference between array and linked list in c?

0 Answers  


Program to find the value of e raised to power x using while loop

5 Answers   IBM, N Tech,


wat is the difference between a definition and declaration? float y;---it looks like a declaration..but it s a definition.how?someone explain

3 Answers   TCS,


how can i get this by using for loop? * ** * **** * ******

3 Answers   Excel,


main() { int a = 65; printf(“%d %o %x”,a,a,a); } Output 65 101 41 Please explain me.How it is coming like that?

3 Answers   Excel,


void main() { int i=5; printf("%d",i++ + ++i); }

21 Answers   ME,


Categories