1.
What will be the output of following program ?
#include
void main()
{
int a=2;
int b=a;
switch(b)
{
case a:
printf("Case-a\n"); break;
case 3:
printf("Case-3\n"); break;
default:
printf("No option\n"); break;
}
printf("Exit from switch");
}
A. Case-2
B. Error
C. Message
Case-2
D. Case-2
Case-3
Exit from switch
Answer: B
-----------------------------------------------------------------------------------------
2.
Can we use string value/variable in switch test condition?
#include
int main()
{
int x;
float y=7.0;
switch(x=y+1)
{
case 8: printf("It's Eight."); break;
default: printf("Oops No choice here!!!");
}
}
A. Error
B. Oops No choice here!!!
C. It's Eight.Oops No choice here!!!
D. It's Eight.
Answer: D
-------------------------------------------------------------------------------------\
3.
Can we use string value/variable in switch test condition?
A. Yes
B. No
Answer: B
--------------------------------------------------------------------------------------
4.
Find the output?
#include
#define TRUE 1
int main()
{
switch(TRUE)
{
printf("Hello");
}
}
A. Hello
B. ERROR
C. No Output
D. Garbage Value
Answer: C
------------------------------------------------------------------------------------------
4.
Find the output?
#include
void main(){
int a=1;
switch(a/2)
{
case NULL:
printf("Case NULL\n");
break;
case 0:
printf("Case ZERO\n");
break;
default:
printf("DEFAULT\n");
break;
}
}
A. Case NULL
B. Case ZERO
C. Case DEFAULT
D. Error
Answer: D
--------------------------------------------------------------------------------------------
5.
Find the output ?
#include
void main(){
static int staticVar;
int j;
for(j=0;j<=5;j+=2)
switch(j){
case 1:
staticVar++;
break;
case 2:
staticVar+=2;
case 4:
staticVar%=2;
j=-1;
continue;
default:
--staticVar;
continue;
}
printf("%d",staticVar);
}
A. 0
B. 1
C. 2
D. Error
Answer: A
--------------------------------------------------------------------------------------------
Next Page
--------------------------------------------------------------------------------------------
More Topics:
Data Types
Operators
Pointers
Array
Preprocessor
Structures
Control Structures