SlideShare uma empresa Scribd logo
1 de 33
CHAPTER 7: STRUCTURES
Outline: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
7.1 Introduction ,[object Object],[object Object],[object Object],[object Object]
7.2 Defining a Structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],struct  tag  { member1 ; member2 ; ... memberN ; };
7.2 Defining a Structure – cont’1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
7.2 Defining a Structure – cont’2 ,[object Object],[object Object],[object Object],[object Object],struct custAccount  { int accNo; char accType; char name[80]; float accBalance; }; struct custAccount oldcust, newcust;
7.2 Defining a Structure – cont’3 ,[object Object],struct custAccount  { int accNo; char accType; char name[80]; float accBalance; } oldcust, newcust;
7.2 Defining a Structure – cont’4 ,[object Object],struct date { int month; int day; int year; }; struct custAccount { int accNo; char accType; char name[80]; float accBalance; struct date payment; } oldcust, newcust; ,[object Object],[object Object]
7.2 Defining a Structure – cont’5
7.3 Defining using  typedef ,[object Object],[object Object],[object Object]
7.3 Defining using  typedef  - cont’1 ,[object Object],[object Object],[object Object]
7.3 Defining using  typedef  - cont’2 ,[object Object],typedef struct  { member1; member2; ...; memberN; } new_type  ,[object Object],[object Object]
7.3 Defining using  typedef  - cont’3 ,[object Object],typedef struct { int accNo; char accType; char name[80]; float accBalance; } record; record oldcust, newcust; ,[object Object],[object Object]
7.3 Defining using  typedef  - cont’3 ,[object Object],[object Object],[object Object],[object Object],typedef struct { int month; int day; int year; } date; typedef struct { int accNo; char accType; char name[80]; float accBalance; date payment; } record; record cust[100];
7.3 Defining using  typedef  - cont’4 ,[object Object],typedef struct { int month; int day; int year; } date; typedef struct { int accNo; char accType; char name[80]; float accBalance; date payment; } record[100]; record cust; typedef struct { int month; int day; int year; } date; struct { int accNo; char accType; char name[80]; float accBalance; date payment; } cust[100];
7.4 Structure Members ,[object Object],[object Object],variable.member variables’ name act as a separator members’ name
7.4 Structure Members  - cont’1 ,[object Object],struct date { int month; int day; int year; }; struct custAccount{ int accNo; char accType; char name[80]; float accBalance; struct date payment; } cust; Example: To access the info. of cust. /* to access the customer’s */ /* account no. */ cust.accNo /* to access the customer’s */ /* name */ cust.name cust.name[2] &cust.name[2] /* to access the month of */ /* the payment of customer */ cust.payment.month
7.5 Initializing Structures ,[object Object],[object Object]
7.5 Initializing Structures – cont’1 ,[object Object],storage_class struct tag variable = {value1, value2, ..., valueN};  Refer to the value of corresponding structure members auto, extern, register, static
7.5 Initializing Structures – cont’1 struct date { int month; int day; int year; }; struct custAccount { int accNo; char accType; char name[80]; float accBalance; struct date payment; }; static  struct custAccount cust= {2345,‘S’,“Khadijah Ismail”,2400.90,9,7,2006}; : Example 7.9
7.5 Initializing Structures – cont’2 Example 7.10:
7.6 Nested Stuctures ,[object Object],[object Object]
7.6 Nested Structures – cont’1 struct employees{ char empName[25]; char  address[30] ; char  city [10] ; char  state[2] ; long int  poscode ; double salary; }; struct customers{ char custName[25]; char  address[30] ; char  city [10] ; char  state[2] ; long int  poscode ; double balance; }; struct addressInfo{ char address[30]; char city [10]; char state[2]; long int poscode; }; struct employees{ char empName[25]; struct addressInfo eAddress; double salary; }e1; struct customers{ char custName[25]; struct addressInfo cAddress; double balance; }c1; Example 7.12: :Example 7.13
7.7 Arrays of Structures ,[object Object],struct date { int month; int day; int year; }; struct custAccount{ int accNo; char accType; char name[80]; float accBalance; struct date payment; } cust[200]; struct date { int month; int day; int year; }; struct custAccount{ int accNo; char accType; char name[80]; float accBalance; struct date payment; }; struct custAccount cust[200]; OR
7.7 Arrays of Structures – cont’2 Example 7.16
7.7 Arrays of Structures – cont’1 ,[object Object],struct student { char name[80]; float courseMark; float finalMark; int TotMark; }; static struct student MarkList[ ] = { “ Kadir”, 45.50, 30.00, 76, "Azizan", 43.50, 30.00, 73, "Xavier", 44.50, 30.00, 75, "Nantha", 46.50, 30.00, 77, "Junani", 42.50, 30.00, 73, "Martha", 42.00, 30.00, 72 } ;
7.8 Structures and Pointers ,[object Object],struct name *ptr ; ,[object Object],struct PersonalData *ptr ; (*ptr).YearOfBirth=20 ; struct PersonalData *ptr ; ptr -> YearOfBirth=20 ; OR
7.8 Structures and Pointers – cont’1 Example 7.16: Example 7.17:
7.9 Passing Structures to Func ,[object Object],[object Object],[object Object]
7.9 Passing Structures … – cont’1 ,[object Object],[object Object],[object Object],[object Object]
7.9 Passing Structures … – cont’2 ,[object Object],[object Object]
7.9 Passing Structures … – cont’3 ,[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath
 

Mais procurados (20)

Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Pointers
PointersPointers
Pointers
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
C pointer
C pointerC pointer
C pointer
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
C Structure and Union in C
C Structure and Union in CC Structure and Union in C
C Structure and Union in C
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 

Destaque (20)

Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Ch8 file processing
Ch8 file processingCh8 file processing
Ch8 file processing
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Ch3 selection
Ch3 selectionCh3 selection
Ch3 selection
 
9 lan
9 lan9 lan
9 lan
 
10 high speedla-ns
10 high speedla-ns10 high speedla-ns
10 high speedla-ns
 
13 atm
13 atm13 atm
13 atm
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
 
6 data linkcontrol
6  data linkcontrol6  data linkcontrol
6 data linkcontrol
 
8 spread spectrum
8 spread spectrum8 spread spectrum
8 spread spectrum
 
5 digital datacomm
5 digital datacomm5 digital datacomm
5 digital datacomm
 
12 wireless la-ns
12 wireless la-ns12 wireless la-ns
12 wireless la-ns
 
AM Receivers
AM ReceiversAM Receivers
AM Receivers
 
11 circuit-packet
11 circuit-packet11 circuit-packet
11 circuit-packet
 
Types of AM Receiver
Types of AM Receiver Types of AM Receiver
Types of AM Receiver
 
Chapter 3 am receivers
Chapter 3 am receiversChapter 3 am receivers
Chapter 3 am receivers
 
4 signal encodingtechniques
4 signal encodingtechniques4 signal encodingtechniques
4 signal encodingtechniques
 
7 multiplexing
7 multiplexing7 multiplexing
7 multiplexing
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulation
 
Protocolos- SMTP, POP3 e IMAP4
Protocolos- SMTP, POP3 e IMAP4Protocolos- SMTP, POP3 e IMAP4
Protocolos- SMTP, POP3 e IMAP4
 

Semelhante a Ch7 structures

Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
TAlha MAlik
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
babuk110
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
rohassanie
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
kavitham66441
 

Semelhante a Ch7 structures (20)

9.structure & union
9.structure & union9.structure & union
9.structure & union
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
12Structures.pptx
12Structures.pptx12Structures.pptx
12Structures.pptx
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
structure .pptx
structure .pptxstructure .pptx
structure .pptx
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
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
 
Chapter 7 (Part I) - User Defined Datatypes.pdf
Chapter 7 (Part I) - User Defined Datatypes.pdfChapter 7 (Part I) - User Defined Datatypes.pdf
Chapter 7 (Part I) - User Defined Datatypes.pdf
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
Lab 13
Lab 13Lab 13
Lab 13
 
C structure and union
C structure and unionC structure and union
C structure and union
 
slideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdfslideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdf
 
Structure In C
Structure In CStructure In C
Structure In C
 
Structures
StructuresStructures
Structures
 

Mais de Hattori Sidek

Mais de Hattori Sidek (10)

Chapter 4 frequency modulation
Chapter 4 frequency modulationChapter 4 frequency modulation
Chapter 4 frequency modulation
 
3. transmission media
3. transmission media3. transmission media
3. transmission media
 
2[1].1 data transmission
2[1].1 data transmission2[1].1 data transmission
2[1].1 data transmission
 
14 congestionin datanetworks
14 congestionin datanetworks14 congestionin datanetworks
14 congestionin datanetworks
 
01 pengenalan
01 pengenalan01 pengenalan
01 pengenalan
 
01 berkenalan
01 berkenalan01 berkenalan
01 berkenalan
 
Comm introduction
Comm introductionComm introduction
Comm introduction
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
Chapter 6 edit
Chapter 6 editChapter 6 edit
Chapter 6 edit
 
Chapter 6 dc motor speed control
Chapter 6 dc motor speed controlChapter 6 dc motor speed control
Chapter 6 dc motor speed control
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

Ch7 structures

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. 7.2 Defining a Structure – cont’5
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. 7.5 Initializing Structures – cont’1 struct date { int month; int day; int year; }; struct custAccount { int accNo; char accType; char name[80]; float accBalance; struct date payment; }; static struct custAccount cust= {2345,‘S’,“Khadijah Ismail”,2400.90,9,7,2006}; : Example 7.9
  • 22. 7.5 Initializing Structures – cont’2 Example 7.10:
  • 23.
  • 24. 7.6 Nested Structures – cont’1 struct employees{ char empName[25]; char address[30] ; char city [10] ; char state[2] ; long int poscode ; double salary; }; struct customers{ char custName[25]; char address[30] ; char city [10] ; char state[2] ; long int poscode ; double balance; }; struct addressInfo{ char address[30]; char city [10]; char state[2]; long int poscode; }; struct employees{ char empName[25]; struct addressInfo eAddress; double salary; }e1; struct customers{ char custName[25]; struct addressInfo cAddress; double balance; }c1; Example 7.12: :Example 7.13
  • 25.
  • 26. 7.7 Arrays of Structures – cont’2 Example 7.16
  • 27.
  • 28.
  • 29. 7.8 Structures and Pointers – cont’1 Example 7.16: Example 7.17:
  • 30.
  • 31.
  • 32.
  • 33.