C
STRUCTURES
Course Code: 24EN1202
Course Instructor:
Dr. Santhosh Kumar G
Academic Year: 2024–2025
Year :1st
Semester : II
Content:
Structures: Purpose and usage of structures. Declaration of
structures. Assignment with structures. Structure variables and
arrays. Nested structures. Student and employee database
implementation using structures.
Examples:
1. For example, a student may have a name(string), age(int), CGPA(float),
graduation year(int/date) and contact details(Ph.No - long int/Address-
string). It is very hard to manage student data with separate variables as
shown(next slide) in the program.
2. For three fields in student record it seems feasible to you. But to store and
manage information of 100 students with different variables is hard i.e.,
name[100][20], age[100], CGPA[100], gyear[100] and addr[100][50].
Details of a particular student will be identified by a same index
Structure definition
The structure is a user-defined data type in C, which is used to store a
collection of different kinds of data i.e., heterogeneous collection of
data
Structure definition
Structure Initialization
Structure Initialization
Structure variable access
The dot (.) operator or membership operator is used to access members of
a structure using a structure variable. Here is the syntax:
C program to read and print coordinates of a 2D-point on cartesian
plane using structure
C program to read and print complex number using structure
Exercise Question
C Program to read and print Employee details(Name, Id, Age and Salary)
using structure
Type defined structure – typedef
In C programming language, typedef is also used with structures. We can define
an alias to the structure (user defined data type) using typedef in C.
C program to read and print coordinates of a 2D-point on cartitian
plane using structure
C program to read and print employee details(name and salary)
using structure
Comparison between Normal and typedef structure definition
Array of structure
ructure variable represents a single record (of an entity) in memory
we want more than one record of structure type, we have to create a
ray of structure variable.
Array of structure
Array of structure
C program to read and print N students record
Operations on structure variable
Operations on structure variable
Operations on structure variable
Nested structure
Nested structure in C is nothing but structure within structure(Like nested
loop). It is used to group composite attributes of an entity. Example
name is a composite attribute consist of First_Name, Middle_Name
and Last_Name.
Nested Structure
Nested Structure
Nested Structure
Example program for Nested structure
Exercise Question
Student and employee database
implementation using structures.