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

More Related Content

PPTX
Structure prespentation
ashu awais
 
PPTX
Chapter 2 part II array and structure.pptx
abenezertekalign118
 
PPTX
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
mahmoud2005rare
 
PDF
Chapter 13.1.9
patcha535
 
PPTX
User defined data types.pptx
Ananthi Palanisamy
 
PPTX
Cs1123 12 structures
TAlha MAlik
 
PPT
Lecture number three Structures (1).ppt
shahbazqadeer1
 
PPTX
Programming in C session 3
Prerna Sharma
 
Structure prespentation
ashu awais
 
Chapter 2 part II array and structure.pptx
abenezertekalign118
 
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
mahmoud2005rare
 
Chapter 13.1.9
patcha535
 
User defined data types.pptx
Ananthi Palanisamy
 
Cs1123 12 structures
TAlha MAlik
 
Lecture number three Structures (1).ppt
shahbazqadeer1
 
Programming in C session 3
Prerna Sharma
 

Similar to Structure.pptx (20)

PDF
unit 5.pdf structure pdf is here you can do this
sofiyakhan0280
 
DOC
Unit 5 (1)
psaravanan1985
 
PPT
CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
meharikiros2
 
PPTX
CHAPTER -4-class and structure.pptx
GebruGetachew2
 
PPTX
detail structure presentation of problem solving
talencorconsultancy
 
PPTX
12Structures.pptx
Aneeskhan326131
 
PPTX
Week2a.pptx
NasirAli233814
 
PPTX
Engineering Computers - L29-Structures.pptx
happycocoman
 
PPT
C Language_PPS_3110003_unit 8ClassPPT.ppt
NikeshaPatel1
 
PPTX
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
PPTX
Ch7Structs.pptx
TalhaLaique1
 
PDF
Structures in c++
Swarup Boro
 
PPTX
Chapter4.pptx
WondimuBantihun1
 
PPT
SPC Unit 5
SIMONTHOMAS S
 
PDF
Structures in c++
Swarup Kumar Boro
 
PDF
Chapter 4 - Structures - Student.pdf - slides
mylinhbangus
 
PPTX
Structures
selvapon
 
PPTX
Structures and Unions
Vijayananda Ratnam Ch
 
PDF
Lk module4 structures
Krishna Nanda
 
PPT
Lecture 04
12802007
 
unit 5.pdf structure pdf is here you can do this
sofiyakhan0280
 
Unit 5 (1)
psaravanan1985
 
CHAPTER-7 C++ PROGRAMMING ( STRUCTURE IN C++)
meharikiros2
 
CHAPTER -4-class and structure.pptx
GebruGetachew2
 
detail structure presentation of problem solving
talencorconsultancy
 
12Structures.pptx
Aneeskhan326131
 
Week2a.pptx
NasirAli233814
 
Engineering Computers - L29-Structures.pptx
happycocoman
 
C Language_PPS_3110003_unit 8ClassPPT.ppt
NikeshaPatel1
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
Ch7Structs.pptx
TalhaLaique1
 
Structures in c++
Swarup Boro
 
Chapter4.pptx
WondimuBantihun1
 
SPC Unit 5
SIMONTHOMAS S
 
Structures in c++
Swarup Kumar Boro
 
Chapter 4 - Structures - Student.pdf - slides
mylinhbangus
 
Structures
selvapon
 
Structures and Unions
Vijayananda Ratnam Ch
 
Lk module4 structures
Krishna Nanda
 
Lecture 04
12802007
 

Recently uploaded (20)

PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 

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;