SlideShare a Scribd company logo
Structures
Definition:
A structure is a collection of similar or different elements
(data types) grouped together
Structure Declaration:
The general form of a structure declaration statement is given
below:
struct structure name
{
structure element 1 ;
structure element 2 ;
structure element 3 ;
......
......
};
Structure variables:
Once the structure is defined, structure variables can be
declared as:
struct structure_name variable 1, variable 2,……., variable n;
E.g.:
struct book
{
char name ;
float price ;
int pages ;
};
struct book b1, b2, b3 ;
Rules of structure declaration
• The closing brace in the structure type declaration must be
followed by a semicolon.
• It is important to understand that a structure type
declaration does not tell the compiler to reserve any space
in memory. All a structure declaration does is, it defines the
‘form’ of the structure.
• Usually structure type declaration appears at the top of the
source code file, before any variables or functions are
defined.
Initialization of structure at the time of declaration
Structure variables can also be initialized where they are
declared. The format used is as follows:
Eg.
struct book
{
char name[10] ;
float price ;
int pages ;
} ;
struct book b1 = { "Maths", 130.00, 550 } ;
struct book b2 = { "Physics", 150.80, 800 } ;
Accessing elements of structure
Structures use a dot (.) operator to access individual elements.
Eg:
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b1, b2, b3 ;
So to refer to pages of the structure defined we have to use,
b1.pages
Similarly, to refer to price we would use,
b1.price
Before the dot there must always be a structure variable and after the
dot there must always be a structure element.
Storing Structure Elements
Whatever be the elements of a structure, they are always stored in
contiguous memory locations.
Eg: struct book
{
char name;
float price ;
int pages ;
} ;
struct book b1 = { "C", 130.00, 550 } ;
For the above structure, the elements are stored in memory as shown:
Elements b1.name b1.price b1.pages
Address 5001 5002 5006
C 130.00 550
C 130.00 550

More Related Content

PPTX
C programing -Structure
PPTX
Presentation on c programing satcture
PPT
Structure in c
PPT
C Structures & Unions
PPTX
Unit 9. Structure and Unions
PPTX
Programming in C session 3
PPTX
CPU : Structures And Unions
PPTX
17 structure-and-union
C programing -Structure
Presentation on c programing satcture
Structure in c
C Structures & Unions
Unit 9. Structure and Unions
Programming in C session 3
CPU : Structures And Unions
17 structure-and-union

What's hot (17)

PPTX
Structure in C
PPTX
Structure in C language
PPTX
#Jai c presentation
PPT
Structure c
PDF
Lecture19 unionsin c.ppt
PPTX
Introduction linked list
PPTX
Structure & Union in C++
PPTX
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
PPT
structures and unions in 'C'
PPT
pointer, structure ,union and intro to file handling
PPTX
Structure & union
PDF
NS Prefix 外伝 … Copy-On-Write #関モバ
PDF
C structure and union
PPT
Unit4 C
PDF
Lk module4 structures
Structure in C
Structure in C language
#Jai c presentation
Structure c
Lecture19 unionsin c.ppt
Introduction linked list
Structure & Union in C++
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
structures and unions in 'C'
pointer, structure ,union and intro to file handling
Structure & union
NS Prefix 外伝 … Copy-On-Write #関モバ
C structure and union
Unit4 C
Lk module4 structures
Ad

Viewers also liked (20)

PPT
JDK1.7 features
PPT
Bowling game kata
PPT
Jdk1.5 Features
PPT
JDK1.6
PDF
Technology radar-may-2013
PPTX
Cs1123 12 structures
PPT
Eee3420 lecture06 rev2011
PPT
Savitch Ch 15
PPT
Savitch ch 01
PDF
Java 5 and 6 New Features
PPT
FP 201 - Unit 3 Part 2
PPTX
INTRODUCTION TO C++, Chapter 1
PPT
Fp201 unit4
PPT
Ch7 structures
PPT
Software Engineering-R.D.Sivakumar
PPT
Basic structure of C++ program
PPT
Structure of C++ - R.D.Sivakumar
PPTX
c++ programming Unit 2 basic structure of a c++ program
PDF
Structures in c++
PPT
Structures
JDK1.7 features
Bowling game kata
Jdk1.5 Features
JDK1.6
Technology radar-may-2013
Cs1123 12 structures
Eee3420 lecture06 rev2011
Savitch Ch 15
Savitch ch 01
Java 5 and 6 New Features
FP 201 - Unit 3 Part 2
INTRODUCTION TO C++, Chapter 1
Fp201 unit4
Ch7 structures
Software Engineering-R.D.Sivakumar
Basic structure of C++ program
Structure of C++ - R.D.Sivakumar
c++ programming Unit 2 basic structure of a c++ program
Structures in c++
Structures
Ad

Similar to Structures bmn (20)

PPT
Lecture number three Structures (1).ppt
PDF
[ITP - Lecture 16] Structures in C/C++
PPTX
Chapter 2 part II array and structure.pptx
PDF
structure and union1.pdf
PDF
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
PPTX
Structure prespentation
PPTX
Unit-V.pptx
PPTX
Structures in C.pptx
PPTX
Data Structures and Algorithms_Updated.pptx
PPTX
U5 SPC.pptx
PPT
Lecture 04
PPT
Structures-in-C programming with examples
PPTX
Definition, Declaration of Structures in C.pptx
PPTX
vkvkhkdflaksjdlfjalkjfaljklajskldjaklsjdklajsdkljaklsjdklajskdljaklsdjklaj
PPT
2 lesson 2 object oriented programming in c++
PPTX
Structures in c language
PPTX
Structures in c language
PPT
Introduction to structures in c lang.ppt
Lecture number three Structures (1).ppt
[ITP - Lecture 16] Structures in C/C++
Chapter 2 part II array and structure.pptx
structure and union1.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
Structure prespentation
Unit-V.pptx
Structures in C.pptx
Data Structures and Algorithms_Updated.pptx
U5 SPC.pptx
Lecture 04
Structures-in-C programming with examples
Definition, Declaration of Structures in C.pptx
vkvkhkdflaksjdlfjalkjfaljklajskldjaklsjdklajsdkljaklsjdklajskdljaklsdjklaj
2 lesson 2 object oriented programming in c++
Structures in c language
Structures in c language
Introduction to structures in c lang.ppt

Recently uploaded (20)

PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Hazard Identification & Risk Assessment .pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Empowerment Technology for Senior High School Guide
PPTX
Lesson notes of climatology university.
PPTX
Introduction to Building Materials
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Cell Types and Its function , kingdom of life
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Hazard Identification & Risk Assessment .pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
What if we spent less time fighting change, and more time building what’s rig...
A systematic review of self-coping strategies used by university students to ...
LDMMIA Reiki Yoga Finals Review Spring Summer
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Empowerment Technology for Senior High School Guide
Lesson notes of climatology university.
Introduction to Building Materials
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Unit 4 Skeletal System.ppt.pptxopresentatiom
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Cell Types and Its function , kingdom of life
Digestion and Absorption of Carbohydrates, Proteina and Fats
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Chinmaya Tiranga quiz Grand Finale.pdf

Structures bmn

  • 1. Structures Definition: A structure is a collection of similar or different elements (data types) grouped together Structure Declaration: The general form of a structure declaration statement is given below: struct structure name { structure element 1 ; structure element 2 ; structure element 3 ; ...... ...... };
  • 2. Structure variables: Once the structure is defined, structure variables can be declared as: struct structure_name variable 1, variable 2,……., variable n; E.g.: struct book { char name ; float price ; int pages ; }; struct book b1, b2, b3 ;
  • 3. Rules of structure declaration • The closing brace in the structure type declaration must be followed by a semicolon. • It is important to understand that a structure type declaration does not tell the compiler to reserve any space in memory. All a structure declaration does is, it defines the ‘form’ of the structure. • Usually structure type declaration appears at the top of the source code file, before any variables or functions are defined.
  • 4. Initialization of structure at the time of declaration Structure variables can also be initialized where they are declared. The format used is as follows: Eg. struct book { char name[10] ; float price ; int pages ; } ; struct book b1 = { "Maths", 130.00, 550 } ; struct book b2 = { "Physics", 150.80, 800 } ;
  • 5. Accessing elements of structure Structures use a dot (.) operator to access individual elements. Eg: struct book { char name ; float price ; int pages ; } ; struct book b1, b2, b3 ; So to refer to pages of the structure defined we have to use, b1.pages Similarly, to refer to price we would use, b1.price Before the dot there must always be a structure variable and after the dot there must always be a structure element.
  • 6. Storing Structure Elements Whatever be the elements of a structure, they are always stored in contiguous memory locations. Eg: struct book { char name; float price ; int pages ; } ; struct book b1 = { "C", 130.00, 550 } ; For the above structure, the elements are stored in memory as shown: Elements b1.name b1.price b1.pages Address 5001 5002 5006 C 130.00 550 C 130.00 550