#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

stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

0 Answers  


A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?

0 Answers  


How can I swap two values without using a temporary?

0 Answers  


how many key words availabel in c a) 28 b) 31 c) 32

0 Answers  


What is malloc calloc and realloc in c?

0 Answers  






#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } what will happen if you executed this code?

4 Answers   Ramco,


What is a constant and types of constants in c?

0 Answers  


i am using gsm modem ! I USE CMGL COMMAND TO DISPLAY THE LIST OF MESSAGES ! I WANT TO READ EACH MESSAGE ONE BY ONE AND GET EACH MESSAGE INDEX USING C PROGRAM ! THE RESPONSE OF THE MODULE AFTER AT+CMGL IS ---CMGL: 1,"REC READ","+85291234567",,"07/05/01,08:00:15+32",145,37 It is easy to list SMS text messages.---- I WANT THE PROGRAM TO GET THE NUMBER "37"{MESSAGE LENGTH} AS WELL AS "1"(MESSAGE INDEX NUMBER" PLEASE HELP

1 Answers   MTNL,


what is the maximum limit of row and column of a matrix in c programming. in linux .

4 Answers   NIIT,


How does #define work?

0 Answers  


what is data structure?

5 Answers   CBSE,


Is c dynamically typed?

0 Answers  


Categories