SlideShare una empresa de Scribd logo
1 de 9
STRUCTURE
WHY STRUCTURE?
 Data structures are a feature that can be used to represent databases, especially if we consider the
possibility of building arrays of them:
 The structure tag can be any legal identifier (but not a keyword).
 The name of a structure type is called the structure tag.
 The identifiers declared inside the braces,{ }, are called member names.
 A structure type definition ends with both a brace, }, and a semicolon.
 Once a structure type definition has been given, the structure type can be used just like the
predefined types int, char, and so forth.
 A structure variable can hold values just like any other variable can hold values.
 A structure value is a collection of smaller values called member values.
 There is one member value for each member name declared in the structure definition.
 A structure definition is usually placed outside of any function definition. The structure type is then available to all the code that
follows the structure definition.
struct Structure_Tag
{
Type_1 Member_Variable_Name_1;
Type_2 Member_Variable_Name_2;
.
.
.
Type_Last Member_Variable_Name_Last;
}[variablename,anothervariableifany]; // }[variablename,anothervariableifany] is optional
 Variables of a structure type can be declared in the same way as variables of other types.
struct course{
string coursename;
string ccode;
int Ects, Chour;
};
INITIALIZATION
Struct Date{
int day, month,year;
};
 Date due_date = {12, 31, 2004};
 Date anotherDate=due_date;
 It is an error if there are more initializers than struct members. If there
 are fewer initializer values than struct members, the provided values are used
 to initialize data members, in order. Each data member without an initializer
 is initialized to a zero value of an appropriate type for the variable.
 The structure type is then available to all the code that follows the structure definition.
 Two or more structure types may use the same member names.
struct FertilizerStock
{
double quantity;
double nitrogen_content;
};
struct CropYield
{
int quantity;
double size;
};
 This coincidence of names will produce no problems. Why?
 The dot operator is used to specify a member variable of a structure variable.
 Structure_Variable_Name.Member_Variable_NameEXAMPLES
 Structure_Variable_Name.Member_Variable_Name
 EXAMPLES
struct StudentRecord
{
int student_number;
char grade;
};
int main( )
{
StudentRecord your_record;
your_record.student_number = 2001;
your_record.grade = 'A';
Some writers call the dot operator the structure member access operator although we will not
use that term.
 You must also place a semicolon after that final brace.
 A structure definition is more than a definition. It can also be used to declare structure variables.
 A function can have call-by-value parameters of a structure type and/or call by-reference parameters of a
structure type.
 A function can have call-by-value parameters of a structure type and/or call by- reference parameters of a
structure type.
 A structure type can also be the type for the value returned by a function.
 Sometimes it makes sense to have structures whose members are themselves smaller structures.
struct Date
{
int month;
int day;
int year;
};
struct PersonInfo
{
double height;//in inches
int weight;//in pounds
Date birthday;
};
PersonInfo person1;
cout << person1.birthday.year;
POINTERS TO ACCESS DATA WITHIN A STRUCTURE.
Date *d;
(*d).month=12;
D-->month=12;
Student * members = new student[100];
//contributions is a structure;
members[i].batch=2009;
Or
*(members+i)-->batch= 2009;
members[i]->batch= 2009; //Using both [] and -> doesn't work
because then you'd be dereferencing twice.
ARRAY OF STRUCTURES
 It is possible to have an array of structures. As StructureName arrayName[size];
 To access arrayName[index].memebervariable
Struct student {
. . .
. . .
} st[100];
To access members you can use st[0].member=value;
e.g.
personInfo persons[100];
persons[0].height=1.83;
persons[5].weight=75;

Más contenido relacionado

Similar a Structure.pptx

Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
Structure in c language
Structure in c languageStructure in c language
Structure in c languagesangrampatil81
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structuresKrishna Nanda
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structureshaibal sharif
 
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.pdfTamiratDejene1
 
Advanced c#
Advanced c#Advanced c#
Advanced c#saranuru
 
structures and unions in 'C'
structures and unions in 'C'structures and unions in 'C'
structures and unions in 'C'illpa
 
Str
StrStr
StrAcad
 
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdfSTRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3Duong Thanh
 
structenumtypedefunion.pptx
structenumtypedefunion.pptxstructenumtypedefunion.pptx
structenumtypedefunion.pptxKUPPALAPADMINI
 

Similar a Structure.pptx (20)

Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 
C structure and union
C structure and unionC structure and union
C structure and union
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
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
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
 
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
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
structures and unions in 'C'
structures and unions in 'C'structures and unions in 'C'
structures and unions in 'C'
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Unit 1_ADC.pptx
Unit 1_ADC.pptxUnit 1_ADC.pptx
Unit 1_ADC.pptx
 
Str
StrStr
Str
 
9.structure & union
9.structure & union9.structure & union
9.structure & union
 
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdfSTRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
 
structenumtypedefunion.pptx
structenumtypedefunion.pptxstructenumtypedefunion.pptx
structenumtypedefunion.pptx
 
Programming in C
Programming in CProgramming in C
Programming in C
 

Último

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Structure.pptx

  • 2.  Data structures are a feature that can be used to represent databases, especially if we consider the possibility of building arrays of them:  The structure tag can be any legal identifier (but not a keyword).  The name of a structure type is called the structure tag.  The identifiers declared inside the braces,{ }, are called member names.  A structure type definition ends with both a brace, }, and a semicolon.  Once a structure type definition has been given, the structure type can be used just like the predefined types int, char, and so forth.  A structure variable can hold values just like any other variable can hold values.
  • 3.  A structure value is a collection of smaller values called member values.  There is one member value for each member name declared in the structure definition.  A structure definition is usually placed outside of any function definition. The structure type is then available to all the code that follows the structure definition. struct Structure_Tag { Type_1 Member_Variable_Name_1; Type_2 Member_Variable_Name_2; . . . Type_Last Member_Variable_Name_Last; }[variablename,anothervariableifany]; // }[variablename,anothervariableifany] is optional  Variables of a structure type can be declared in the same way as variables of other types. struct course{ string coursename; string ccode; int Ects, Chour; };
  • 4. INITIALIZATION Struct Date{ int day, month,year; };  Date due_date = {12, 31, 2004};  Date anotherDate=due_date;  It is an error if there are more initializers than struct members. If there  are fewer initializer values than struct members, the provided values are used  to initialize data members, in order. Each data member without an initializer  is initialized to a zero value of an appropriate type for the variable.
  • 5.  The structure type is then available to all the code that follows the structure definition.  Two or more structure types may use the same member names. struct FertilizerStock { double quantity; double nitrogen_content; }; struct CropYield { int quantity; double size; };  This coincidence of names will produce no problems. Why?
  • 6.  The dot operator is used to specify a member variable of a structure variable.  Structure_Variable_Name.Member_Variable_NameEXAMPLES  Structure_Variable_Name.Member_Variable_Name  EXAMPLES struct StudentRecord { int student_number; char grade; }; int main( ) { StudentRecord your_record; your_record.student_number = 2001; your_record.grade = 'A'; Some writers call the dot operator the structure member access operator although we will not use that term.
  • 7.  You must also place a semicolon after that final brace.  A structure definition is more than a definition. It can also be used to declare structure variables.  A function can have call-by-value parameters of a structure type and/or call by-reference parameters of a structure type.  A function can have call-by-value parameters of a structure type and/or call by- reference parameters of a structure type.  A structure type can also be the type for the value returned by a function.  Sometimes it makes sense to have structures whose members are themselves smaller structures.
  • 8. struct Date { int month; int day; int year; }; struct PersonInfo { double height;//in inches int weight;//in pounds Date birthday; }; PersonInfo person1; cout << person1.birthday.year; POINTERS TO ACCESS DATA WITHIN A STRUCTURE. Date *d; (*d).month=12; D-->month=12; Student * members = new student[100]; //contributions is a structure; members[i].batch=2009; Or *(members+i)-->batch= 2009; members[i]->batch= 2009; //Using both [] and -> doesn't work because then you'd be dereferencing twice.
  • 9. ARRAY OF STRUCTURES  It is possible to have an array of structures. As StructureName arrayName[size];  To access arrayName[index].memebervariable Struct student { . . . . . . } st[100]; To access members you can use st[0].member=value; e.g. personInfo persons[100]; persons[0].height=1.83; persons[5].weight=75;