Structure and Union 413
SU MM AR Y
This chapter explains the concept of structure and programs. One of the powerful features of C language
is that it supports the creation of Structure. The various features of Structure are described at the
beginning of this chapter. For the beginners the concepts and examples on Structures are given in an
easy way and step by step process is adopted. The various titles under structure such as how the
Structures are declared, initialized, Structure within the Structure, Array of Structure, Pointer to Structure
are elaborated. Also how functions are defined in Structure are also illustrated with good examples.
The TYPEDEF facility can be used for creating user-defined data types and illustrated with many
examples. Enumerated data type, Union etc are the important subtitles of this chapter. Enumerated
data type provides user-defined data types. Union is a principal method by which the programmer
can derive dissimilar data types. The last but not least the
DOS and ROM-BIOS functions and their
applications are explained. The user is advised to go through the appendix C where by using these
functions a number of programs can be developed. If the reader executes the programs from this
chapter it will be of immense use for other applications.
EXERC ISES
A] Answ er the following questions.
1
2
3
4
5
6
8
9
10
11
12
13
14
What is a structure in C? How structure is declared?
What is the use of struct keyword? Explain the use of dot operator.
How are structure elements stored in memory?
Explain nested structure. Draw diagram to explain nested structure.
How are arrays of structure variables defined. How are they beneficial to the programmer?
How are structure elements accessed using pointer? Which operator is used?
Is it possible to pass structure variable to function? Explain in detail the possible Ways.
How are user-defined data types defined?
Explain the importance of bit fields. How do bit fields saves memory space?
Explain enumerated data type.
What is a union in C? How is data stored using union?
What are the differences between union and structure?
Explain REGS and SREGS unions. List any five CPU registers of each union type.
Explain in t 8 6 () and in tdos () functions. How are they used to interact with hardware?
B) Answer the follow ing by selecting the appropriate option.
1) Identify the most appropriate sentence to describe unions
a) unions contain members of different data types which share the same storage area in
memory
b) unions are like structures
c) unions are less frequently used in the program
d) unions are used for set operations
2) The member variable of structure are accessed by using
a) dot (.) operator b) arrow (-> ) operator
c) asterisk (*) operator d) ampersand (&) operator