1. What is the output of this C code?
-
#include <stdio.h>
-
const int a = 1, b = 2;
-
int main()
-
{
-
int x = 1;
-
switch (x)
-
{
-
case a:
-
printf("yes ");
-
case b:
-
printf("non");
-
break;
-
}
-
}
a) yes no
b) yes
c) no
d) Compile time error
Answer
Answer: d [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
#define max(a) a
-
int main()
-
{
-
int x = 1;
-
switch (x)
-
{
-
case max(2):
-
printf("yesn");
-
case max(1):
-
printf("non");
-
break;
-
}
-
}
a) yes no
b) yes
c) no
d) Compile time error
Answer
Answer: c [Reason:] None.
3. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
switch (printf("Do"))
-
{
-
case 1:
-
printf("Firstn");
-
break;
-
case 2:
-
printf("Secondn");
-
break;
-
default:
-
printf("Defaultn");
-
break;
-
}
-
}
a) Do
b) DoFirst
c) DoSecond
d) DoDefault
Answer
Answer: c [Reason:] None.
4. Comment on the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int a = 1;
-
switch (a)
-
case 1:
-
printf("%d", a);
-
case 2:
-
printf("%d", a);
-
case 3:
-
printf("%d", a);
-
default:
-
printf("%d", a);
-
}
a) No error, output is 1111
b) No error, output is 1
c) Compile time error, no break statements
d) Compile time error, case label outside switch statement
Answer
Answer: d [Reason:] None.
5. Switch statement accepts.
a) int
b) char
c) long
d) all of the mentioned
Answer
Answer: d [Reason:] None.
6. Comment on the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int a = 1;
-
switch (a)
-
{
-
case a:
-
printf("Case A ");
-
default:
-
printf("Default");
-
}
-
}
a) Output: Case A
b) Output: Default
c) Output: Case A Default
d) Compile time error
Answer
Answer: d [Reason:] None.
7. Comment on the output of this C code?
-
#include <stdio.h>
-
switch (ch)
-
{
-
case 'a':
-
case 'A':
-
printf("true");
-
}
a) if (ch == ‘a’ && ch == ‘A’) printf(“true”);
b) if (ch == ‘a’)
if (ch == ‘a’) printf(“true”);
c) if (ch == ‘a’ || ch == ‘A’) printf(“true”);
d) none of the mentioned
Answer
Answer: c [Reason:] None.