- What is the output of C Program?
# include <stdio.h>
int main()
{
int k=64;
switch(k)
{
case k<64: printf(“SHIP “); break; case k>=64:
printf(“BOAT “);
break;
default:
printf(“PETROL”);
}
printf(“CHILLY”);
}
A) BOAT CHILLY
B) BOAT PETROL CHILLY
C) SHIP BOAT CHILLY
D) Compiler error
Answer D
- What is the output of C Program with switch statement or block?
# include <stdio.h>
int main()
{
int k=8;
switch(k)
{
case 1==8:
printf(“ROSE “);
break;
case 1 && 2:
printf(“JASMINE “);
break;
default:
printf(“FLOWER “);
}
printf(“GARDEN”);
}
A) ROSE GARGEN
B) JASMINE GARDEN
C) FLOWER GARDEN
D) Compiler error
Answer C
3. What is the output of C Program?
# include <stdio.h>
int main()
{
int k=25;
switch(k) {
case 24:
printf(“ROSE “);
break;
case 25:
printf(“JASMINE “);
continue;
default:
printf(“FLOWER “);
}
printf(“GARDEN”);
}
A) JASMINE GARDEN
B) JASMINE FLOWER GARDEN
C) FLOWER GARDEN
D) Compiler error
Answer D
4. What is the output of C Program with switch statement?
# include <stdio.h>
int main()
{
switch(24.5) {
case 24.5:
printf(“SILVER “);
break;
case 25.0:
printf(“GOLD “);
break;
default:
printf(“TIN “);
}
printf(“COPPER”);
}
A) SILVER COPPER
B) TIN COPPER
C) COPPER
D) Compiler error
Answer D
- What will be the output of the following C code?
(Assuming that we have entered the value 1 in the standard input)
#include <stdio.h>
int main()
{
double ch;
printf(“Enter a value between 1 to 2 : “);
scanf(“%lf”, &ch);
switch (ch)
{
case 1 :
printf(“1”);
break;
case 2 :
printf(“2”);
break;
}
retrurn 0;
}
a) Compile time error
b) 1
c) 2
d) Varies
Answer A
- What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input)
#include <stdio.h>
int main( )
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
break;
printf(“hi”);
default:
printf(“2\n”);
}
return 0;
}
a) 1
b) hi 2
c) Run time error
d) 2
Answer D - What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)
#include <stdio.h>
int main( )
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch, ch + 1)
{
case 1:
printf(“1”);
break;
case 2:
printf(“2”);
break;
}
return 0;
}
a) 1
b) 2
c) 3
d) Run time error
Answer B - What will be the output of the following C code?
#include <stdio.h>
int main( )
{
int x = 97;
switch (x)
{
case ‘a’:
printf(“yes “);
break;
case 97:
printf(“no\n”);
break;
}
a) yes
b) yes no
c) Duplicate case value error
d) Character case value error
Answer C - What will be the output of the following C code?
#include <stdio.h>
int main( )
{
printf(“%d “, 1);
goto l1;
printf(“%d “, 2);
l1:goto l2;
printf(“%d “, 3);
l2:printf(“%d “, 4);
return 0;
}
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Answer A - What will be the output of the following C code?
#include <stdio.h>
int main( )
{
printf(“%d “, 1);
goto l1;
printf(“%d “, 2);
return 0;
}
void foo()
{
l1 : printf(“3 “, 3);
}
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
Answer D - What will be the output of the following C code?
#include <stdio.h>
int main( )
{
int i = 0, j = 0;
while (i < 2)
{
l1 : i++;
while (j < 3)
{
printf(“Loop\n”);
goto l1;
}
}
return 0;
}
a) Loop Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
Answer D
C MCQ Set-4 Explanation - What will be the output of the following C code?
#include <stdio.h>
int main( )
{
int i = 0, j = 0;
while (l1: i < 2)
{
i++;
while (j < 3)
{
printf(“loop\n”);
goto l1;
}
}
return 0;
}
a) loop loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop
Answer B - What will be the output of the following C code?
#include <stdio.h>
int main( )
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
printf(“loop\n”);
goto l1;
}
}
return 0;
}
a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop
Answer A - Choose a correct statement about a C Switch Construct.
A) default case is optional inside switch.
B) break; causes the control to exit the switch immediately and avoid fall down to other CASE statements.
C) You can not use duplicate CASE Constants inside a Switch construct.
D) All the above.
Answer D
C MCQ Set-4 Explanation - What will be the output of the following C code?
# include <stdio.h>
int main( )
{
int i = 0, k;
if (i == 0)
goto label;
for (k = 0; k< 3; k++)
{
printf (“hi\n”);
label : k = printf ( “%03d”, i);
}
return 0;
}
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0
Answer A
C MCQ Set-4 Explanation