SlideShare a Scribd company logo
Structure and Union
Topics
 Introduction
 Structure Definition
 Giving values to Members
 Structure Initialization
 Array of Structures
 Arrays within Structure
Introduction
 Arrays can be used to represent a group of
data items that belong to the same type.
However, if we want to represent a collection
of data items of different types using a single
name then we cannot use an array.
 C supports a user defined data type
structure for packing data of different types.
A structure is a convenient tool for handling
a group of logically related data items.
Structure Definition
 The general format of structure is:
struct tag_name
{
data_type member1;
data_type member2;
-----------
-----------
};
 Ex: struct student
{
char name[20];
int roll;
float gpa;
};
Continue…
 We can declare structure variables using the tag
name anywhere in the program. For example:
struct student s1,s2,s3;
 Each of the variable has three members and the
members are not variable.
 The declaration can be:
struct student
{
char name[20];
int roll;
float gpa;
}s1,s2,s3;
Giving values To members
 The link between a member and a variable is
established using the member operator (.).
 For example: s1.name is the variable representing
the name of s1 and can be treated like any other
ordinary variable.
 We can assign values to the members of s1:
strcpy(s1.name, “Rahul”);
s1.roll=1;
s1.gpa=3.79;
 We can use scanf to give values through the
keyboard.
scanf(“%s”,s1.name);
scanf(“%d”,&s1.roll);
Structure Initialization
 Like any other data type, a structure variable can
be initialized. A structure must be declared as
static if it is to be initialized inside a function.
 Ex:
main()
{
static struct
{
int x;
float y;
}str={101,350.789};
---------
}
Continue..
 Another method is to initialize a structure variable
outside the function:
struct st
{
int x;
float y;
}s={50,101.56};
main()
{
static struct st s1={200,340.50};
------------
}
Array of Structure
 We use structures to describe the format of
a number of related variables. We may
declare an array of structures, each element
of the array representing a structure variable
 For example:
struct student st[100]; defines an array
called st that consists of 100 elements.
Each element is defined to be of the type
struct student.
Structures within Structures
 Structure within a structure means nesting of structures.
 Ex:
struct st
{
char name[20];
char dept[20];
struct
{
int roll;
float gpa;
}info;
}student;
 We can use the members like student.info.roll,
student.info.gpa, student.name
Continue…
 We can also use tag names to define inner
structures. Example-
struct info
{
int roll;
float gpa;
};
struct st
{
char name[20];
struct info str;
};
struct st student[20];
Union
 Unions are the same syntax as the structure
However, there is major distinction between
them in terms of storage.
Structure Union
Every member of the
structure occupy the
memory space
The space of the largest
member will occupy for
the union
There is no limitation for
using the member
Only one member can
handle at a time

More Related Content

What's hot

C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
shaibal sharif
 
Structure & Union in C++
Structure & Union in C++Structure & Union in C++
Structure & Union in C++
Davinder Kaur
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
Structure & union
Structure & unionStructure & union
Structure & union
Rupesh Mishra
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
Structure in c
Structure in cStructure in c
Structure in c
Prabhu Govind
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
Prerna Sharma
 
Structures
StructuresStructures
Structures
DrJasmineBeulahG
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
Ram Sagar Mourya
 
Files,blocks and functions in R
Files,blocks and functions in RFiles,blocks and functions in R
Files,blocks and functions in R
Vladimir Bakhrushin
 
Array in c
Array in cArray in c
Array in c
AnIsh Kumar
 
Day 2b i/o.pptx
Day 2b   i/o.pptxDay 2b   i/o.pptx
Day 2b i/o.pptx
Adrien Melquiond
 
03 structures
03 structures03 structures
03 structures
Rajan Gautam
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
Dr Nisha Arora
 
Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
Rupak Roy
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
MohammedShameer28
 
Day 2 repeats.pptx
Day 2 repeats.pptxDay 2 repeats.pptx
Day 2 repeats.pptx
Adrien Melquiond
 

What's hot (20)

C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Structure & Union in C++
Structure & Union in C++Structure & Union in C++
Structure & Union in C++
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
Structure in c
Structure in cStructure in c
Structure in c
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
 
Structure in c
Structure in cStructure in c
Structure in c
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Structures
StructuresStructures
Structures
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Files,blocks and functions in R
Files,blocks and functions in RFiles,blocks and functions in R
Files,blocks and functions in R
 
Array in c
Array in cArray in c
Array in c
 
Day 2b i/o.pptx
Day 2b   i/o.pptxDay 2b   i/o.pptx
Day 2b i/o.pptx
 
03 structures
03 structures03 structures
03 structures
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
 
Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
 
Day 2 repeats.pptx
Day 2 repeats.pptxDay 2 repeats.pptx
Day 2 repeats.pptx
 

Viewers also liked

IS 151 Lecture 3
IS 151 Lecture 3IS 151 Lecture 3
IS 151 Lecture 3
wajanga
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7
wajanga
 
IS 151 - Lecture 3
IS 151 - Lecture 3IS 151 - Lecture 3
IS 151 - Lecture 3
wajanga
 
Chapter one
Chapter oneChapter one
Chapter one
kiran acharya
 
IS 151 Lecture 2
IS 151 Lecture 2IS 151 Lecture 2
IS 151 Lecture 2
wajanga
 
aaالمملكة العربية السعودية
aaالمملكة العربية السعوديةaaالمملكة العربية السعودية
aaالمملكة العربية السعوديةabdullah259
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C languageLogical and Conditional Operator In C language
Logical and Conditional Operator In C language
Abdul Rehman
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
Logic gates
Logic gatesLogic gates
Logic gates
prasanna chitra
 
Hierarchical Memory System
Hierarchical Memory SystemHierarchical Memory System
Hierarchical Memory System
Jenny Galino
 
Memory Hierarchy
Memory HierarchyMemory Hierarchy
Memory Hierarchy
Trinity Dwarka
 
Truth tables
Truth tablesTruth tables
Truth tableswalkerlj
 
C pointer
C pointerC pointer
Introduction to compilers
Introduction to compilersIntroduction to compilers
Introduction to compilers
Bilal Maqbool ツ
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
Ram Sagar Mourya
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
Abhilash Nair
 
Loaders
LoadersLoaders
Basic electronics
Basic electronicsBasic electronics
Basic electronics
Mantra VLSI
 

Viewers also liked (20)

IS 151 Lecture 3
IS 151 Lecture 3IS 151 Lecture 3
IS 151 Lecture 3
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7
 
IS 151 - Lecture 3
IS 151 - Lecture 3IS 151 - Lecture 3
IS 151 - Lecture 3
 
Truth table analysis
Truth table analysisTruth table analysis
Truth table analysis
 
Chapter one
Chapter oneChapter one
Chapter one
 
IS 151 Lecture 2
IS 151 Lecture 2IS 151 Lecture 2
IS 151 Lecture 2
 
Cd unit i
Cd unit iCd unit i
Cd unit i
 
aaالمملكة العربية السعودية
aaالمملكة العربية السعوديةaaالمملكة العربية السعودية
aaالمملكة العربية السعودية
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C languageLogical and Conditional Operator In C language
Logical and Conditional Operator In C language
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Logic gates
Logic gatesLogic gates
Logic gates
 
Hierarchical Memory System
Hierarchical Memory SystemHierarchical Memory System
Hierarchical Memory System
 
Memory Hierarchy
Memory HierarchyMemory Hierarchy
Memory Hierarchy
 
Truth tables
Truth tablesTruth tables
Truth tables
 
C pointer
C pointerC pointer
C pointer
 
Introduction to compilers
Introduction to compilersIntroduction to compilers
Introduction to compilers
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
 
Loaders
LoadersLoaders
Loaders
 
Basic electronics
Basic electronicsBasic electronics
Basic electronics
 

Similar to Chap 10(structure and unions)

Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
Structure In C
Structure In CStructure In C
Structure In C
yndaravind
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
Gem WeBlog
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)mrecedu
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
psaravanan1985
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
YOGESH SINGH
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
ansariparveen06
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
ParinayWadhwa
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
Krishna Nanda
 
structures.ppt
structures.pptstructures.ppt
structures.ppt
RamyaR163211
 
Introduction to structures in c lang.ppt
Introduction to structures in c lang.pptIntroduction to structures in c lang.ppt
Introduction to structures in c lang.ppt
shivani366010
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
Dhrumil Patel
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
sudhakargeruganti
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
Tanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
Sheik Mohideen
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
WondimuBantihun1
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
Mehul Desai
 

Similar to Chap 10(structure and unions) (20)

Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
Structure In C
Structure In CStructure In C
Structure In C
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
structures.ppt
structures.pptstructures.ppt
structures.ppt
 
Introduction to structures in c lang.ppt
Introduction to structures in c lang.pptIntroduction to structures in c lang.ppt
Introduction to structures in c lang.ppt
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Antenna (2)
Antenna (2)Antenna (2)
Antenna (2)
 
Voltage suppler..
Voltage suppler..Voltage suppler..
Voltage suppler..
 
Number system
Number systemNumber system
Number system
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
Computer hardware ppt1
 
# Operating system
# Operating system# Operating system
# Operating system
 
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 3
 
Magnetism 2
Magnetism 2Magnetism 2
Magnetism 2
 
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
2. sinusoidal waves
 
Magnetism 1
Magnetism 1Magnetism 1
Magnetism 1
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Landownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptxLandownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptx
JezreelCabil2
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Landownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptxLandownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 

Chap 10(structure and unions)

  • 1. Structure and Union Topics  Introduction  Structure Definition  Giving values to Members  Structure Initialization  Array of Structures  Arrays within Structure
  • 2. Introduction  Arrays can be used to represent a group of data items that belong to the same type. However, if we want to represent a collection of data items of different types using a single name then we cannot use an array.  C supports a user defined data type structure for packing data of different types. A structure is a convenient tool for handling a group of logically related data items.
  • 3. Structure Definition  The general format of structure is: struct tag_name { data_type member1; data_type member2; ----------- ----------- };  Ex: struct student { char name[20]; int roll; float gpa; };
  • 4. Continue…  We can declare structure variables using the tag name anywhere in the program. For example: struct student s1,s2,s3;  Each of the variable has three members and the members are not variable.  The declaration can be: struct student { char name[20]; int roll; float gpa; }s1,s2,s3;
  • 5. Giving values To members  The link between a member and a variable is established using the member operator (.).  For example: s1.name is the variable representing the name of s1 and can be treated like any other ordinary variable.  We can assign values to the members of s1: strcpy(s1.name, “Rahul”); s1.roll=1; s1.gpa=3.79;  We can use scanf to give values through the keyboard. scanf(“%s”,s1.name); scanf(“%d”,&s1.roll);
  • 6. Structure Initialization  Like any other data type, a structure variable can be initialized. A structure must be declared as static if it is to be initialized inside a function.  Ex: main() { static struct { int x; float y; }str={101,350.789}; --------- }
  • 7. Continue..  Another method is to initialize a structure variable outside the function: struct st { int x; float y; }s={50,101.56}; main() { static struct st s1={200,340.50}; ------------ }
  • 8. Array of Structure  We use structures to describe the format of a number of related variables. We may declare an array of structures, each element of the array representing a structure variable  For example: struct student st[100]; defines an array called st that consists of 100 elements. Each element is defined to be of the type struct student.
  • 9. Structures within Structures  Structure within a structure means nesting of structures.  Ex: struct st { char name[20]; char dept[20]; struct { int roll; float gpa; }info; }student;  We can use the members like student.info.roll, student.info.gpa, student.name
  • 10. Continue…  We can also use tag names to define inner structures. Example- struct info { int roll; float gpa; }; struct st { char name[20]; struct info str; }; struct st student[20];
  • 11. Union  Unions are the same syntax as the structure However, there is major distinction between them in terms of storage. Structure Union Every member of the structure occupy the memory space The space of the largest member will occupy for the union There is no limitation for using the member Only one member can handle at a time