Structures in C
Structures in C
Presented by,
Name University Roll no
Aniruddha Das 35000324048
Soumyadeep Mondal 35000324061
Barnita Das 35000324055
Amit Das 35000324056
Trinni ghosh 35000324037
Agenda
Introduction 1
Defining structures 2
typedef for Structures 3
Array of Structures 4
Summary 5
1 Introduction
// Example
#include <stdio.h>
In C, a structure is a user- // Defining a structure
defined data type that can be struct A {
used to group items of int x;
};
possibly different types into a
single type. int main() {
The struct keyword is used to
define a structure. The items // Creating a structure
variable
in the structure are called struct A a;
its member and they can be of // Initializing member
any valid data type. a.x = 11;
printf("%d", a.x);
return 0;
}
// output = 11
2 Defining structures
There are two steps of creating a structure in C:
1. Structure Definition
2. Creating Structure Variables
Structure Definition
A structure is defined using the struct keyword
followed by the structure name and its members.
It is also called a structure template or
structure prototype, and no memory is allocated
to the structure in the declaration.
struct structure_name { structure_name: Name of the structure.
data_type1 member1; member1, member2, …: Name of the
data_type2 member2; members.
… data_type1, data_type2, …: Type of the
}; members.
Creating Structure Variable
struct structure_name {
…
}var1, var2….;
Basic Operations of Structure