Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Structures and union

Total questions: 15

Worksheet time: 20mins

Name
Class
Date
1.

Which among the following is never possible in C when members in a structure are same as that in a union?    

//Let P be a structure    

//Let Q be a union

a)

a.sizeof(P) is greater than sizeof(Q)

b)

b. sizeof(P) is equal to sizeof(Q)

c)

c. sizeof(P) is less than to sizeof(Q)

d)

d. None of the above

2.

Which of the following are themselves a collection of different data types?

a)

String

b)

Structure

c)

Integer

d)

None of these

3.

Which of the following cannot be a structure member?

a)

Another structure

b)

Array

c)

Function

d)

None of these

4.

What is the output of this C code?

#include <stdio.h>

struct student

{

int no; char name[20];

};

void main()

{ student s;

s.no = 8;

printf("hello");

}

a)

Hello

b)

Nothing

c)

Compilation error

5.

Which of the following share a similarity in syntax?    

  1. Union, 2. Structure, 3. Arrays and 4. Pointers

a)

1 & 2

b)

3&4

c)

1&3

d)

2&3

6.

For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?struct temp

{

int a : 13;

int b : 8;

int c : x;

}s;

a)

4

b)

8

c)

12

d)

16

7.

Which operator connects the structure name to its member name?

a)

-

b)

.

c)

=>

d)

@

8.

What will be the output of the following C code?

#include <stdio.h>

struct student

{

char *name;

};

struct student s;

struct student fun(void)

{

s.name = "newton";

printf("%s\n", s.name);

s.name = "alan";

return s;

}

void main()

{

struct student m = fun();

printf("%s\n", m.name);

m.name = "turing";

printf("%s\n", s.name);

}

a)

Alan alan newton

b)

Newton alan alan

c)

Alan newton alan

d)

Compile time error

9.

What will be the output of the below coding #include <stdio.h>

struct temp

{

int a;

} s;

void func(struct temp s)

{

s.a = 10;

printf("%d\t", s.a);

}

main()

{

func(s);

printf("%d\t", s.a);

}

a)

10,garbage value

b)

Garbage value,10

c)

0,10

d)

10,0

10.

Size of the following union (assume size of int=2, size of float=4 and size of char=1);

union ABC

{

int a;

float b;

char c;

};

a)

2

b)

4

c)

1

d)

8

11.

What is wrong with the following code?

struct Person{ char name; struct Person *Mother, *Father; }Anita;

a)

The ; should appear after the } and Anita be defined later

b)

name should be defined as an array

c)

There is no error in the code

d)

struct Person Mother, Father; must be defined as struct Person Mother, Father;

12.

What will be the output of the following code?

struct { int a;

double d;

float cp;

}s;

void main()

{

printf("%d\t%d\t%d\t%d", sizeof(s.a), sizeof(s.d), sizeof(s.cp), sizeof(s));

}

a)

4,8,4,24

b)

4,4,8,8

c)

4,8,24,8

d)

4,4,4,28

13.

What is important difference between structure & union?

a)

There is no difference

b)

Union takes less memory then structure

c)

Union woks faster then structure

d)

Structure takes less memory then union

14.

Is it necessary that all elements of structure should be different

a)

Yes

b)

No

15.

Which of the following accesses a variable in structure b?

a)

b->var

b)

b.var

c)

b*var

d)

b-var