NEW
Font size
S
M
L
XL
WorksheetsSASI -1st year -DAY1-AN(19.12.23)
Total questions: 15
Worksheet time: 15mins
Name
Class
Date
1.
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
default:
printf("2\n");
}
}
a)
1
b)
2
c)
1 2
d)
Run time error
2.
#include <stdio.h>
void 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");
}
}
a)
1
b)
hi 2
c)
Run time error
d)
2
3.
#include <stdio.h>
int main()
{
int a = 1, b = 1;
switch (a)
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
}
a)
yes
b)
no
c)
Compile time error
d)
yes no
4.
#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
5.
#include <stdio.h>
int main()
{
float f = 1;
switch (f)
{
case 1.0:
printf("yes\n");
break;
default:
printf("default\n");
}
}
a)
yes
b)
yes defined behaviour
c)
undefined behaviour
d)
compile time error
6.
#include <stdio.h>
#define max(a) a
int main()
{
int x = 1;
switch (x)
{
case max(2):
printf("yes\n");
case max(1):
printf("no\n");
break;
}
}
a)
yes no
b)
yes
c)
no
d)
compile time error
7.
#include <stdio.h>
int main()
{
switch (printf("Do"))
{
case 1:
printf("First\n");
break;
case 2:
printf("Second\n");
break;
default:
printf("Default\n");
break;
}
}
a)
Do
b)
DoFirst
c)
DoSecond
d)
DoDefault
8.
#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
9.
Which datatype can accept the switch statement?
a)
int
b)
char
c)
long
d)
all of the mentioned
10.
#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)
Output: Case A Default
11.
#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
12.
#include <stdio.h>
void 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;
}
}
a)
Compile time error
b)
1
c)
2
d)
varies
13.
#include <stdio.h>
void main()
{
char *ch;
printf("enter a value between 1 to 3:");
scanf("%s", ch);
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}
a)
1
b)
Compile time error
c)
1
d)
Run Time Error
14.
#include <stdio.h>
void main()
{
int ch=1;
switch (ch, ch + 1)
{
case 1:
printf("1\n");
break;
case 2:
printf("2");
break;
}
} }
a)
1
b)
2
c)
3
d)
4
15.
int main();
{
int a=3;
switch(a)
{
}
printf("MySwitch");
}
a)
My switch
b)
No output
c)
Compile Error
d)
None of the above
Reset
