#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

Write a C program to check a number even or odd, without using any relational, arithmetic operator and any loops.

1 Answers  


what is the diffrenet bettwen HTTP and internet protocol

0 Answers  


wat is the difference between array and pointer?

4 Answers   Wipro,


What is difference between structure and union in c programming?

0 Answers  


wat is output of the following int main() { const int j=2; int i; switch(i) { case 1:break; case j:break; default:break; } }

2 Answers  






please give me some tips for the placement in the TCS.

0 Answers   TCS,


What is self-referential structure in c programming?

0 Answers  


1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?

0 Answers   KPIT,


i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical

0 Answers  


How can I increase the allowable number of simultaneously open files?

1 Answers   ABC,


macros and function are related in what aspect? a)recursion b)varying no of arguments c)hypochecking d)type declaration

12 Answers   HCL, Infosys, Microsoft,


What is the difference between int main and void main in c?

0 Answers  


Categories