wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C - Structures

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Which of the following operation is illegal in structures?

a)

Typecasting of structure

b)

Pointer to a variable of same structure

c)

Dynamic allocation of memory for structure

d)

All of the mentioned

2.

What is the size of a C structure?

a)

C structure is always 128 bytes

b)

Size of C structure is the total bytes of all elements of structure

c)

Size of C structure is the size of largest element

d)

None of the above

3.

Which operator connects the structure name to its member name?

a)

-

b)

.

c)

/

d)

\

4.

Which of the following cannot be a structure member?

a)

Another structure

b)

Array

c)

Function

d)

None of the mentioned

5.

Number of bytes in memory taken by the below structure is?

struct test

{

int k;

char c;

};

a)

Multiple of integer size

b)

integer size+character size

c)

Depends on the platform

d)

Multiple of word size

6.

Size of a union is determined by size of the

a)

Biggest member in the union

b)

First member in the union

c)

Last member in the union

d)

Sum of the sizes of all members

7.

A C structure or User defined datatype is also called ________.

a)

Derived data type

b)

Secondary data type

c)

Aggregate data type

d)

All the above

8.

Members of a union are accessed as_____________.

a)

union-name.member

b)

union-pointer->member

c)

Both a & b

d)

None of the mentioned

9.

Choose a correct statement about C structures

a)

Structure elements can be initialized at the time of declaration

b)

Structure members can not be initialized at the time of declaration

c)

Only integer members of structure can be initialized at the time of declaraion

d)

None of the above

10.

What is the output of C program?

#include <stdio.h>

int main()

{

structure hotel

{

int items;

char name[10];

}a;

strcpy(a.name, "TAJ");

a.items=10;

printf("%s", a.name);

return 0;

}

a)

TAJ

b)

Empty string

c)

Compiler error

d)

None of the above

11.

What is the output of C program?

#include <stdio.h>

int main()

{

struct book

{

int pages;

char name[10];

}a;

a.pages=10;

strcpy(a.name,"Cbasics");

printf("%s=%d", a.name,a.pages);

return 0;

}

a)

empty string=10

b)

Cbasics=10

c)

C=basics

d)

Compiler error

12.

What is the output of C program?

#include <stdio.h>

int main()

{

struct ship

{

int size;

char color[10];

}boat1, boat2;

boat1.size=10;

boat2 = boat1;

printf("boat2=%d",boat2.size);

return 0;

}

a)

boat2=10

b)

boat2=-1

c)

boat2=0

d)

Compiler error

13.

What is the output of C program with structures?

#include <stdio.h>

int main()

{

struct ship

{

char color[10];

}boat1, boat2;

strcpy(boat1.color,"RED");

printf("%s ",boat1.color);

boat2 = boat1;

strcpy(boat2.color,"YELLOW");

printf("%s",boat1.color);

return 0;

}

a)

RED RED

b)

RED YELLOW

c)

YELLOW YELLOW

d)

Compiler error

14.

What is the output of c program with structures?

#include <stdio.h>

int main()

{

struct tree

{

int h;

int w;

};

struct tree tree1={10};

printf("%d ",tree1.w);

printf("%d",tree1.h);

return 0;

}

a)

0 0

b)

10 0

c)

0 10

d)

10 10

15.

What is the output of C program?

#include <stdio.h>

int main()

{

struct laptop

{

int cost;

char brand[10];

};

struct laptop L1={5000,"ACER"};

struct laptop L2={6000,"IBM"};

printf("Name=%s",L1.brand);

return 0;

}

a)

Name=ACER

b)

Name=

c)

Compiler error

d)

None of the above

16.

What is the output of C program with Structure pointer in C?

#include <stdio.h>

int main()

{

struct books{

int pages;

char str[4];

}*ptr;

printf("%d",sizeof(ptr));

return 0;

}

a)

2

b)

6

c)

7

d)

4

17.

What is the output of C program with structures pointers?

#include <stdio.h>

int main()

{

struct forest

{

int trees;

int animals;

}F1,*F2;

F1.trees=1000;

F1.animals=20;

F2=&F1;

printf("%d ",F2.animals);

return 0;

}

a)

0

b)

20

c)

Compiler error

d)

None of the above

18.

What is the output of this C program?

int main()

{

struct bus

{

int seats;

}F1, *F2;

F1.seats=20;

F2=&F1;

F2->seats=15;

printf("%d ",F1.seats);

return 0;

}

a)

15

b)

20

c)

0

d)

Compiler Error

19.

What is the output of C program with structure array pointers?

#include <stdio.h>

int main()

{

struct car

{

int km;

}*p1[2];

struct car c1={1234};

p1[0]=&c1;

printf("%d ",p1[0]->km);

return 0;

}

a)

0

b)

1

c)

1234

d)

Compiler error

20.

What is a structure in C language?

a)

A structure is a collection of elements that can be of same data type

b)

A structure is a collection of elements that can be of different data type

c)

Elements of a structure are called members

d)

All the above