#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

Is main a keyword in c?

0 Answers  


What is this infamous null pointer, anyway?

0 Answers  


Explain what is wrong with this statement? Myname = ?robin?;

0 Answers  


What should be keep precautions while using the recursion method?

1 Answers  


Add 2 64 bit numbers on a 32 bit machine

3 Answers   EMC, Hyderabad Central University, NetApp,






What is sizeof return in c?

0 Answers  


How many types of operator or there in c?

0 Answers  


When can you use a pointer with a function?

0 Answers  


void main() { int *ptr; ptr = (int *) 0x400 ; printf("ptr=%d",ptr); } output?

1 Answers  


how do u find out the number of 1's in the binary representation of a decimal number without converting it into binary(i mean without dividing by 2 and finding out the remainder)? three lines of c code s there it seems...can anyone help

5 Answers  


Why c is faster than c++?

0 Answers  


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

0 Answers  


Categories