wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DSBS-AN-29.01.2024

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.
#include<stdio.h> main() { typedef int a; a b=2, c=8, d; d=(b*2)/2+8; printf("%d",d); }
a)
10
b)
16
c)
8
d)
error
2.
#include<stdio.h> #include<string.h> typedef struct employee { char name[50]; int salary; } e1; void main( ) { printf("Enter Employee name"); scanf("%s",e1.name); printf("\n%s",e1.name); }
a)
world.name
b)
nworld
c)
world
d)
error
3.
What is the size of myArray in the code shown below? (Assume that 1 character occupies 1 byte) typedef char x[10]; x myArray[5];
a)
5bytes
b)
10bytes
c)
40 bytes
d)
50 bytes
4.
#include<stdio.h> int main() { typedef union a { int i; char ch[2]; }hello; hello u; u.ch[0] = 3; u.ch[1] = 2; printf("%d, %d", u.ch[0], u.ch[1]); return 0; }
a)
2, 3
b)
3, 2
c)
32
d)
error
5.
#include<stdio.h> int main() { typedef union a { int i; char ch[2]; }hello; hello u; u.ch[0] = 3; u.ch[1] = 2; printf("%d, %d", u.ch[0], u.ch[1]); return 0; }
a)
20
b)
10
c)
5
d)
2
6.
#include <stdio.h> typedef int Arr[4]; // Driver code int main() { Arr temp = { 10, 20, 30, 40 }; printf("typedef using an array\n"); for (int i = 0; i < 4; i++) { printf("%d ", temp[i]); } return 0; }
a)
typedef using an array 10 20 30 40
b)
typedef using an array 30 40 10 20
c)
typedef using an array 40 30 20 10
d)
compile time error
7.
Which member of the union will be active after REF LINE in the following C code? #include <stdio.h> union temp { int a; float b; char c; }; union temp s = {1,2.5,’A’};
a)
a
b)
b
c)
c
d)
Such declaration are illegal
8.
What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1) #include <stdio.h> union uTemp { double a; int b[10]; char c; }u;
a)
4
b)
8
c)
40
d)
80
9.
What will be the output of the following C code (Assuming size of int and float is 4)? #include <stdio.h> union { int ival; float fval; } u; void main() { printf("%d", sizeof(u)); }
a)
16
b)
4
c)
8
d)
32
10.
#include <stdio.h> union stu { int ival; float fval; }; void main() { union stu r; r.ival = 5; printf("%d", r.ival); }
a)
9
b)
compile time error
c)
16
d)
5
11.
#include <stdio.h> union { int x; char y; }p; int main() { p.y = 60; printf("%d\n", sizeof(p)); }
a)
Compile time error
b)
sizeof(int) + sizeof(char)
c)
Depends on the compiler
d)
sizeof(char)
12.
#include <stdio.h> union p { int x; char y; }k = {1, 97}; int main() { printf("%d\n", k.y); }
a)
Compile time error
b)
97
c)
a
d)
1
13.
Which of the following share a similarity in syntax? 1. Union, 2. Structure, 3. Arrays and 4. Pointers
a)
1 and 3
b)
1 and 2
c)
3 and 4
d)
1,3 and 4
14.
What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8) #include <stdio.h> union utemp { int a; double b; char c; }u; int main() { u.c = 'A'; u.a = 1; printf("%d", sizeof(u)); }
a)
1
b)
4
c)
8
d)
13
15.
#include <stdio.h> int main() { union { int i1; int i2; } myVar = {.i2 = 100}; printf("%d %d", myVar.i1, myVar.i2); return 0; }
a)
Compile error due to incorrect syntax of initialization
b)
No compile error and it’ll print “0 100”.
c)
No compile error and it’ll print “100 100”.
d)
compile time error