Quiz

1. Which statement is used in Switch to prevent fall through.
2. break
continue
exit
else

3. Every switch construct can be replaced by a series of if-else statements
4. True
False

5. In an if-else construct, curly braces can be ignored for the else part if the block contains only one statement
6. True
False

7. An if-else construct can be replaced by a set of if constructs
8. True
False

9. The default scope of the if statement is only the next statement.
10. True
False

11. For every if block there is always a corresponding else block
12. True
False

13. What will be the output for this code:
14.                      void main(){
int x=1;
if(x--)
printf("Hi");
else
printf("Bye");
}

Hi
Bye
HiBye
Invalid Syntax

15. What will be the output for this code:
16.                       void main(){
int x=1;
if(--x)
printf("Hi");
else
printf("Bye");
}

Hi
Bye
HiBye
Invalid Syntax

17. What will be the output for this code:
18.                       void main(){
int x=1;
if(x=2)
printf("Hi");
else
printf("Bye");
}

Hi
Bye
HiBye
Invalid Syntax

19. What will be the output for this code:
20.                  void main(){
int a=100;
if(a > 10)
printf("Dhoni");
else if(a > 20)
printf("Hussey");
else if(a > 30)
printf("De villiers");
}

Dhoni
Hussey
De villers
Invalid Syntax

21. What will be the output for this code:
22.
void main(){
int m=5,n=10,q=20;
if(q/n*m)
printf("A");
else
printf("B");
printf("C");
}

A
B
AC
BC

23. Float expressions are allowed in switch cases
24. Yes
No

25. Switch cases works faster than equivalent if-else ladder
26. True
False

27. The case keyword is followed by an integer or a character constant.
28. True
Flase

29. What will be the output for this code:
30.                 main( )
{
int c = 1 ;
switch ( c )
{
case 1 :
printf ( "I " ) ;
case 2 :
printf ( "Love " ) ;
case 3:
printf ( "Programming") ;
}

}

I
Love
Programming
I Love Programming

31. What will be the output for this code:
32.                 main( )
{
int c = 3 ;
switch ( c )
{
case 1 :
printf ( "I " ) ;
break;
case 2 :
printf ( "Love " ) ;
break;
case 3:
printf ( "Programming ") ;
}

}

I
Love
Programming
I Love Programming

33. What will be the output for this code:
34.                 main( )
{
int c = 3 ;
if(c%3)
printf("Hi")
else
printf("Bye")

}

Hi
Bye
Invalid Syntax
HiBye

35. What will be the output for this code:
36.                 main( )
{
int a=1,b=2 ;
if(a-- == 0)
printf("Hi")
if(--b == 1)
printf("Bye")

}

Hi
Bye
Invalid Syntax
HiBye

37. What will be the output for this code:
38.                 main( )
{
int a=1,b=0 ;
if(a||b)
printf("Hi");
if(a && b)
printf("Bye");
if(~b)
printf("Hello");
}

Hi
Bye
HiHello
HiBye

39. What will be the output for this code:
40.                 main( )
{
int a=100 ;
if((a << 2) == 102))
printf("Hello");
printf("World");

}

Hello
World
HelloWorld
Invalid Syntax