Welcome Guest | Sign in | Register

Home > C Programming > Switch-case > Questions and Answers

01. What will be the output of the following program?
#include
void main()
{ int a = 2;
switch(a)
{ case 1:
printf("goodbye"); break;
case 2:
continue;
case 3:
printf("bye");
}
}
A. error B. goodbye
C. bye D. byegoodbye

Answer and Explanation

Answer: error

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What will be the output of the following program?
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
A. GOOD B. BAD
C. Compiler Error D. No Output

Answer and Explanation

Answer: Compiler Error

Explanation:

Compiler Error: Constant expression required in function main.
The case statement can have only constant expressions .Enumerated types can be used in case statements.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Which follows the case statement?
A. : B. ;
C. - D. A newline

Answer and Explanation

Answer: :

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What is required to avoid falling through from one case to the next?
A. end B. break
C. Stop D. A semicolon.

Answer and Explanation

Answer: break

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What keyword covers unhandled possibilities?
A. all B. contingency
C. default D. other

Answer and Explanation

Answer: default

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What is the result of the following code?
int x=0;

switch(x)
{
case 1: printf( "One" );
case 0: printf( "Zero" );
case 2: printf( "Hello World" );
}
A. One B. Zero
C. Hello World D. ZeroHello World

Answer and Explanation

Answer: ZeroHello World

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. Rewrite the following statements using a switch statement

if( letter == 'X' )
sum = 0;
else if ( letter == 'Z' )
valid_flag = 1;
else if( letter == 'A' )
sum = 1;
else
printf("Unknown letter -->%c\n", letter );
A. Statement 1
switch( letter ) {
case 'X' : sum = 0; break;
case 'Z' : valid_flag = 1; break;
case 'A' : sum = 1; break;
default : printf( "Unknown letter -->%c\n", letter ); break;
}
B. Statement 2
switch( letter ) {
case 'X' : sum = 0;
case 'Z' : valid_flag = 1;
case 'A' : sum = 1;
default : printf( "Unknown letter -->%c\n", letter );
}
C. Statement 3
switch( letter ) {
case "X" : sum = 0; break;
case "Z" : valid_flag = 1; break;
case "A" : sum = 1; break;
default : printf( "Unknown letter -->%c\n", letter ); break;
}
D. None of these

Answer and Explanation

Answer: Statement 1
switch( letter ) {
case 'X' : sum = 0; break;
case 'Z' : valid_flag = 1; break;
case 'A' : sum = 1; break;
default : printf( "Unknown letter -->%c\n", letter ); break;
}

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. What would be the output if option = 'H'?
switch(option)
{
case 'H' : printf("Hello");
case 'W' : printf("Welcome");
case 'B' : printf("Bye");
break;
}
A. Hello B. Hello Welcome
C. Hello Welcome Bye D. None of the above

Answer and Explanation

Answer: Hello Welcome Bye

Explanation:
If option = H then the first case is true so "Hello" gets printed but there is no break statement after this case to come out of the switch statement so the program execute all other case statements also and Hello Welcome Bye get printed.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. What is the output of the following program?
void main(){
int a=1;
while(a++<=1)
while(a++<=2);
printf("%d",a);
}
A. 2 B. 3
C. 4 D. 5

Answer and Explanation

Answer: 5

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. What is the output of the following program?

void main(){
int a;
a=1;
while(a<=1)
if(a%2)
printf("%d",a++);
printf("%d",a+10);
}
A. 2 11 B. 1 11
C. 2 12 D. 1 12

Answer and Explanation

Answer: 1 12

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.