SlideShare a Scribd company logo
1 of 30
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
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 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;
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

What's hot (20)

Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Enums in c
Enums in cEnums in c
Enums in c
 
String functions in C
String functions in CString functions in C
String functions in C
 
C string
C stringC string
C string
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 

Viewers also liked (8)

Structure c
Structure cStructure c
Structure c
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Strings in C
Strings in CStrings in C
Strings in C
 
Structure in c
Structure in cStructure in c
Structure in c
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Array in c language
Array in c languageArray in c language
Array in c language
 
String c
String cString c
String c
 
String in c
String in cString in c
String in c
 

Similar to Structure in C

Similar to Structure in C (20)

User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
 
Structures
StructuresStructures
Structures
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
1. structure
1. structure1. structure
1. structure
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
Structure
StructureStructure
Structure
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Pointers and Structures.pptx
Pointers and Structures.pptxPointers and Structures.pptx
Pointers and Structures.pptx
 
Structure In C
Structure In CStructure In C
Structure In C
 
Structures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptxStructures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptx
 
Struct
StructStruct
Struct
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
Structures in C
Structures in CStructures in C
Structures in C
 
C structure and union
C structure and unionC structure and union
C structure and union
 
Structures
StructuresStructures
Structures
 
637225564198396290.pdf
637225564198396290.pdf637225564198396290.pdf
637225564198396290.pdf
 

More from Fazle Rabbi Ador

Online Shopping Agent in AI
Online Shopping Agent in AIOnline Shopping Agent in AI
Online Shopping Agent in AIFazle Rabbi Ador
 
00 java basic programming in Bangla|| Introduction
00 java basic programming in Bangla|| Introduction00 java basic programming in Bangla|| Introduction
00 java basic programming in Bangla|| IntroductionFazle Rabbi Ador
 
Types of memory in Computer
Types of memory in ComputerTypes of memory in Computer
Types of memory in ComputerFazle Rabbi Ador
 
Error Finding in Numerical method
Error Finding in Numerical methodError Finding in Numerical method
Error Finding in Numerical methodFazle Rabbi Ador
 
Data Mining & Applications
Data Mining & ApplicationsData Mining & Applications
Data Mining & ApplicationsFazle Rabbi Ador
 
Electromagnetic induction & useful applications
Electromagnetic induction & useful applicationsElectromagnetic induction & useful applications
Electromagnetic induction & useful applicationsFazle Rabbi Ador
 
Application of mathematics in daily life
Application of mathematics in daily lifeApplication of mathematics in daily life
Application of mathematics in daily lifeFazle Rabbi Ador
 
Application of mathematics in daily life
Application of mathematics in daily lifeApplication of mathematics in daily life
Application of mathematics in daily lifeFazle Rabbi Ador
 

More from Fazle Rabbi Ador (12)

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

Recently uploaded

Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...ssuserf63bd7
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Seán Kennedy
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Cathrine Wilhelmsen
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...GQ Research
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSINGmarianagonzalez07
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 

Recently uploaded (20)

Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 

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
  • 8.
  • 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:
  • 12.
  • 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;
  • 18.
  • 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)