SlideShare a Scribd company logo
STRUCTURESTRUCTURE in CC
programming…
Group : ASTUTE
Soummo Supriya : 151-15-4741
T.M. Ashikur Rahman : 151-15-4971
Md. Fazle Rabbi Ador : 151-15-5482
Tasnuva Tabassum Oshin : 151-15-4673
Masumer Rahman : 151-15-5040
Introduction
• Md. Fazle Rabbi adoR
• 151-15-5482
Structure
• A structure is a collection of variables of
different data types under a single name.
• The variables are called members of the
structure.
• The structure is also called a user-defined
data type.
3
Defining a Structure
• Syntax:
struct structure_name
{
data_type member_variable1;
data_type member_variable2;
………………………………;
data_type member_variableN;
};
Note: The members of a structure do not occupy
memory until they are associated with a
structure_variable.
4
struct student
{
char name[20];
int roll_no;
float marks;
char gender;
long int phone_no;
};
•Multiple variables of struct student type can be
declared as:
struct student st1, st2, st3; 5
Example
Defining a structure…Defining a structure…
• Each variable of structure has its own
copy of member variables.
• The member variables are accessed using
the dot (.) operator or member operator.
• For example: st1.name is member
variable name of st1 structure variable
while st3.gender is member variable
gender of st3 structure variable.
6
struct student
{
char name[20];
int ID;
float CSE_marks;
char gender;
long int phone_no;
};
void main()
{
struct student st1={"Ishtiaque",5482,13.5,'M',16021548};
struct student st2={"Oshin",4288,15,'F',19845321};
printf ("Name: %s ID: %d CSE Marks: %.1f Gender: %c Phn: %d
n",st1.name,st1.ID,st1.CSE_marks,st1.gender,st1.phone_no);
printf ("Name: %s ID: %d CSE Marks: %.1f Gender: %c Phn: %d
n",st2.name,st2.ID,st2.CSE_marks,st2.gender,st2.phone_no);
}
7
Structure in C
Pointers to structurePointers to structure
A pointer is a memory address.
You can define pointers to
structures in very similar way as
you define pointer to any other
variable
Prepared By Soummo Spriya
151-15-4741
Declaration of pointers
• Referencing pointer to
another address to access
memory
• Using dynamic memory
allocation
Structure's member through
pointer can be used in two ways:
Structure in C
““Structure within anotherStructure within another
StructureStructure
(Nested Structure)”(Nested Structure)”
Md.Masumer Rahman
Id: 151-15-5040
What is Nested Structure
• Nested structure in C is nothing but structure within
structure. One structure can be declared inside other
structure as we declare structure members inside a
structure. The structure variables can be a normal
structure variable or a pointer variable to access the
data.
• Nested Structures are allowed in C Programming
Language.
• We can write one Structure inside another structure
as member of another structure.
Let’s see the structure declaration below,
Way 1: Declare two separate structures
struct date
{
int date;
int month;
int year;
};
struct Employee
{
char ename[20];
int ssn;
float salary;
struct date doj;
}
emp1;
Way 2 : Declare Embedded structures
struct Employee
{
char ename[20];
int ssn;
float salary;
struct date
{
int date;
int month;
int year;
}
doj;
}
emp1;
Structure in C
Function and Structure
Name: T.m.
ashikur rahmaN
id: 151-15-4971
Function and Structure
We will consider four cases
here:
Passing the individual member to
functions
 Passing whole structure to functions
Passing structure pointer to functions
Passing array of structure to functions
Passing the individual member to
functions
 Structure members can be
passed to functions as actual
arguments in function call
like ordinary variables.
PASSING WHOLE STRUCTURE TO
FUNCTIONS
 Whole structure can be passed to a function
by the syntax:
function _ name ( structure _ variable _
name );
 The called function has the form:
return _ type function _ name (struct tag _ name
structure _ variable _ name)
{
…………;
}
Passing structure pointer to
functions
 In this case, address of structure
variable is passed as an actual argument
to a function.
The corresponding formal argument must
be a structure type pointer variable.
Passing array of structure to function
 Passing an array of structure type to a
function is similar to passing an array of
any type to a function.
 That is, the name of the array of
structure is passed by the calling function
which is the base address of the array of
structure.
 Note: The function prototype comes after
the structure definition.
Arrays of structuresArrays of structures
• Tasnuva Tabassum Oshin
• 151-15-4673
Arrays of structures
• An ordinary array: One type of data
• An array of structs: Multiple types of data
in each array element.
0 1 2 … 98 99
0 1 2 … 98 99
Arrays of structures
• We often use arrays of structures.
• Example:
StudentRecord Class[100];
strcpy(Class[98].Name, “bangladeshi man");
Class[98].Id = 12345;
strcpy(Class[98].Dept, "COMP");
Class[98].gender = 'M';
Class[0] = Class[98]; Bangladeshi man
12345 M
COMP
. . .
0 1 2 … 98 99
Arrays inside structures
• We can use arrays inside structures.
• Example:
struct square{
point vertex[4];
};
square Sq;
• Assign values to Sq using the given square
x y x y x y x y
(4, 3) (10, 3)
(4, 1) (10, 1)
Structure in C
Structure in C

More Related Content

PPTX
Structure in C language
PPTX
Pointers in C Programming
PPTX
Dynamic memory allocation in c
PPTX
C programing -Structure
PPTX
Presentation on c structures
PPTX
Dynamic memory allocation
PPTX
Pointer in C++
PPTX
C Structures and Unions
Structure in C language
Pointers in C Programming
Dynamic memory allocation in c
C programing -Structure
Presentation on c structures
Dynamic memory allocation
Pointer in C++
C Structures and Unions

What's hot (20)

PPTX
Pointer arithmetic in c
PPTX
Structures in c language
PDF
Introduction to c++ ppt
PPTX
Structure in c language
PPT
Linked lists
PPTX
This pointer
PPTX
Constructor and Types of Constructors
PPTX
Union in c language
PPTX
Unit 3. Input and Output
PPT
Constants in C Programming
PPT
Structure c
PPTX
PPTX
Pointers in c - Mohammad Salman
PPTX
String in c programming
PPTX
PPT
structure and union
PPTX
Arrays in c
PPTX
Functions in c
PDF
Constructors and destructors
PPTX
C Programming: Structure and Union
Pointer arithmetic in c
Structures in c language
Introduction to c++ ppt
Structure in c language
Linked lists
This pointer
Constructor and Types of Constructors
Union in c language
Unit 3. Input and Output
Constants in C Programming
Structure c
Pointers in c - Mohammad Salman
String in c programming
structure and union
Arrays in c
Functions in c
Constructors and destructors
C Programming: Structure and Union
Ad

Viewers also liked (8)

PPT
Structure of a C program
PPTX
Strings in C
PPTX
Arrays in C language
PPTX
Array in c language
PPT
DOC
String in c
Structure of a C program
Strings in C
Arrays in C language
Array in c language
String in c
Ad

Similar to Structure in C (20)

PPTX
Presentation on c programing satcture
PDF
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
PPTX
Programming for problem solving-II(UNIT-2).pptx
PPT
structure.ppt
PDF
Structures in c++
PPTX
Module 5-Structure and Union
PDF
Structures in c++
PDF
Lk module4 structures
PPT
C Language_PPS_3110003_unit 8ClassPPT.ppt
PPTX
Structures in C
PPTX
Data Structures and Algorithms_Updated.pptx
PPTX
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
PPTX
Structures in c language
PPTX
STRUCTURES IN C PROGRAMMING
DOCX
C programming structures & union
PDF
Structures and Pointers
PDF
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
PPT
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handling
PPTX
Chapter 8 Structure Part 2 (1).pptx
PPT
Structure and union
Presentation on c programing satcture
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Programming for problem solving-II(UNIT-2).pptx
structure.ppt
Structures in c++
Module 5-Structure and Union
Structures in c++
Lk module4 structures
C Language_PPS_3110003_unit 8ClassPPT.ppt
Structures in C
Data Structures and Algorithms_Updated.pptx
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
Structures in c language
STRUCTURES IN C PROGRAMMING
C programming structures & union
Structures and Pointers
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handling
Chapter 8 Structure Part 2 (1).pptx
Structure and union

More from Fazle Rabbi Ador (12)

PPTX
Online Shopping Agent in AI
PPTX
00 java basic programming in Bangla|| Introduction
PPTX
Types of memory in Computer
PPTX
Error Finding in Numerical method
PPTX
Cloning Bio-Informative
PPTX
Amd Athlon Processors
PPTX
Data Mining & Applications
PPTX
Electromagnetic induction & useful applications
PPTX
Bangladesh Cricket Team.
PPTX
Application of mathematics in daily life
PPTX
Application of mathematics in daily life
PPTX
SIXTH SENSE-TECHNOLOGY
Online Shopping Agent in AI
00 java basic programming in Bangla|| Introduction
Types of memory in Computer
Error Finding in Numerical method
Cloning Bio-Informative
Amd Athlon Processors
Data Mining & Applications
Electromagnetic induction & useful applications
Bangladesh Cricket Team.
Application of mathematics in daily life
Application of mathematics in daily life
SIXTH SENSE-TECHNOLOGY

Recently uploaded (20)

PDF
Business Analytics and business intelligence.pdf
PDF
Mega Projects Data Mega Projects Data
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PDF
Clinical guidelines as a resource for EBP(1).pdf
PDF
.pdf is not working space design for the following data for the following dat...
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
Database Infoormation System (DBIS).pptx
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
Business Analytics and business intelligence.pdf
Mega Projects Data Mega Projects Data
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Clinical guidelines as a resource for EBP(1).pdf
.pdf is not working space design for the following data for the following dat...
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Miokarditis (Inflamasi pada Otot Jantung)
Database Infoormation System (DBIS).pptx
Acceptance and paychological effects of mandatory extra coach I classes.pptx
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Qualitative Qantitative and Mixed Methods.pptx
Business Ppt On Nestle.pptx huunnnhhgfvu
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Supervised vs unsupervised machine learning algorithms
Data_Analytics_and_PowerBI_Presentation.pptx

Structure in C

  • 1. STRUCTURESTRUCTURE in CC programming… Group : ASTUTE Soummo Supriya : 151-15-4741 T.M. Ashikur Rahman : 151-15-4971 Md. Fazle Rabbi Ador : 151-15-5482 Tasnuva Tabassum Oshin : 151-15-4673 Masumer Rahman : 151-15-5040
  • 2. Introduction • Md. Fazle Rabbi adoR • 151-15-5482
  • 3. Structure • A structure is a collection of variables of different data types under a single name. • The variables are called members of the structure. • The structure is also called a user-defined data type. 3
  • 4. Defining a Structure • Syntax: struct structure_name { data_type member_variable1; data_type member_variable2; ………………………………; data_type member_variableN; }; Note: The members of a structure do not occupy memory until they are associated with a structure_variable. 4
  • 5. struct student { char name[20]; int roll_no; float marks; char gender; long int phone_no; }; •Multiple variables of struct student type can be declared as: struct student st1, st2, st3; 5 Example
  • 6. Defining a structure…Defining a structure… • Each variable of structure has its own copy of member variables. • The member variables are accessed using the dot (.) operator or member operator. • For example: st1.name is member variable name of st1 structure variable while st3.gender is member variable gender of st3 structure variable. 6
  • 7. struct student { char name[20]; int ID; float CSE_marks; char gender; long int phone_no; }; void main() { struct student st1={"Ishtiaque",5482,13.5,'M',16021548}; struct student st2={"Oshin",4288,15,'F',19845321}; printf ("Name: %s ID: %d CSE Marks: %.1f Gender: %c Phn: %d n",st1.name,st1.ID,st1.CSE_marks,st1.gender,st1.phone_no); printf ("Name: %s ID: %d CSE Marks: %.1f Gender: %c Phn: %d n",st2.name,st2.ID,st2.CSE_marks,st2.gender,st2.phone_no); } 7
  • 9. Pointers to structurePointers to structure A pointer is a memory address. You can define pointers to structures in very similar way as you define pointer to any other variable Prepared By Soummo Spriya 151-15-4741
  • 11. • Referencing pointer to another address to access memory • Using dynamic memory allocation Structure's member through pointer can be used in two ways:
  • 13. ““Structure within anotherStructure within another StructureStructure (Nested Structure)”(Nested Structure)” Md.Masumer Rahman Id: 151-15-5040
  • 14. What is Nested Structure • Nested structure in C is nothing but structure within structure. One structure can be declared inside other structure as we declare structure members inside a structure. The structure variables can be a normal structure variable or a pointer variable to access the data. • Nested Structures are allowed in C Programming Language. • We can write one Structure inside another structure as member of another structure.
  • 15. Let’s see the structure declaration below,
  • 16. Way 1: Declare two separate structures struct date { int date; int month; int year; }; struct Employee { char ename[20]; int ssn; float salary; struct date doj; } emp1;
  • 17. Way 2 : Declare Embedded structures struct Employee { char ename[20]; int ssn; float salary; struct date { int date; int month; int year; } doj; } emp1;
  • 19. Function and Structure Name: T.m. ashikur rahmaN id: 151-15-4971
  • 20. Function and Structure We will consider four cases here: Passing the individual member to functions  Passing whole structure to functions Passing structure pointer to functions Passing array of structure to functions
  • 21. Passing the individual member to functions  Structure members can be passed to functions as actual arguments in function call like ordinary variables.
  • 22. PASSING WHOLE STRUCTURE TO FUNCTIONS  Whole structure can be passed to a function by the syntax: function _ name ( structure _ variable _ name );  The called function has the form: return _ type function _ name (struct tag _ name structure _ variable _ name) { …………; }
  • 23. Passing structure pointer to functions  In this case, address of structure variable is passed as an actual argument to a function. The corresponding formal argument must be a structure type pointer variable.
  • 24. Passing array of structure to function  Passing an array of structure type to a function is similar to passing an array of any type to a function.  That is, the name of the array of structure is passed by the calling function which is the base address of the array of structure.  Note: The function prototype comes after the structure definition.
  • 25. Arrays of structuresArrays of structures • Tasnuva Tabassum Oshin • 151-15-4673
  • 26. Arrays of structures • An ordinary array: One type of data • An array of structs: Multiple types of data in each array element. 0 1 2 … 98 99 0 1 2 … 98 99
  • 27. Arrays of structures • We often use arrays of structures. • Example: StudentRecord Class[100]; strcpy(Class[98].Name, “bangladeshi man"); Class[98].Id = 12345; strcpy(Class[98].Dept, "COMP"); Class[98].gender = 'M'; Class[0] = Class[98]; Bangladeshi man 12345 M COMP . . . 0 1 2 … 98 99
  • 28. Arrays inside structures • We can use arrays inside structures. • Example: struct square{ point vertex[4]; }; square Sq; • Assign values to Sq using the given square x y x y x y x y (4, 3) (10, 3) (4, 1) (10, 1)