Structure And Union


A Structure is a user defined data type that can store related information together. The variable
within a structure are of different data types and each has a name that is used to select it from the
structure. C arrays allow you to define type of variables that can hold several data items of the
same kind but structure is another user defined data type available in C programming, which
allows you to combine data items of different kinds.

Structures are used to represent a record, Suppose you want to keep track of your books in a
library. You might want to track the following attributes about each book:
• Title
• Author
• Subject
• Book ID

Structure Declaration
It is declared using a keyword struct followed by the name of the structure. The variables of the
structure are declared within the structure.

 Struct struct-name
 data_type var-name;
 data_type var-name;

Structure Initialization
Assigning constants to the members of the structure is called initializing of structure.

struct struct_name
 data _type member_name1;
 data _type member_name2;

Accessing the Members of a structure
A structure member variable is generally accessed using a ‘.’ operator.
Syntax: strcut_var.

The dot operator is used to select a particular member of the structure. To assign value to the

Data members of the structure variable stud, we write,

To input values for data members of the structure variable stud, can be written as,


To print the values of structure variable stud, can be written as:


Try Now – Programming In C MCQs