#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

hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

0 Answers   Reliance,


can we print any string in c language without using semicolon(;)(terminator) in whole program.

11 Answers  


What is new line escape sequence?

0 Answers  


how can I convert a string to a number?

0 Answers  


main() { int i,j,A; for(A=-1;A<=1;A++) prinf("%d\t",!!A); }

6 Answers  






What is the output of the below program and how it is? void main() { static int var=5; printf("%d",var--); if(var) main(); }

8 Answers   MindFire, TCS, Tech Mahindra,


Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent

0 Answers  


Explain what is the benefit of using #define to declare a constant?

0 Answers  


Which is best linux os?

0 Answers  


What are the 3 types of structures?

0 Answers  


what is the most appropriate way to write a multi-statement macro?

1 Answers  


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?

3 Answers  


Categories