SlideShare a Scribd company logo
1 of 29
Structures
Introduction to Structure
Problem: – How to group together a collection
of data items of different types that are
logically related to a particular entity???
Example: Student Type which contains name,
rollno, marks of six subjects, total, average.
Solution: Structure
Structure contd…
• A structure is a collection of
variables of different data types
under a single name.
• The variables are called members of
the structure.
• The structure is also called a user-
defined data type.
Structure
• Definition
• Declaration
• Accessing a structure members
• Structure initialization
Defining a Structure
• Syntax:
struct structure_name
{
data_type member_variable1;
data_type member_variable2;
………………………………;
data_type member_variableN;
};
Example 1
Defining a Structure for Student
struct student
{
char name[20];
int roll_no;
int m1,m2,m3;
int tot;
float avg;
};
Example 2
Defining a Structure for Employee
struct employee
{
char name[20];
int e_id;
int sal;
};
Example 3
Defining a Structure for Product
struct product
{
char prod_name[20];
int p_id;
int p_price;
};
Example 4
Defining a Structure for Time
struct time
{
int hour;
int min;
int sec;
};
Question
Defining a Structure for Book
• Create a Structure for book which contains
book name, book issn number, price of the
book, net quantity available
Requirement Data Type
book name String (array of
characters) size=50
book issn number String (array of
characters) size =10
price of the book int
net quantity
available
int
Answer
Defining a Structure for Book
struct book
{
char b_name[50];
char ssn_no[50];
int price;
int quanity;
};
Declaring structure variable
Syntax: struct structure_name structure_variable;
Example (Student Structure Definition)
struct student
{
char name[20];
int roll_no;
int m1,m2,m3;
int tot;
float avg;
};
Student Structure Variable Declaration
struct student s1;
Declaring structure variable
Example (employee Structure Definition)
struct employee
{
char name[20];
int e_id;
int sal;
};
Employee Structure Variable Declaration
struct employee e1,e2[10];
Declaring structure variable
Example (product Structure Definition)
struct product
{
char prod_name[20];
int p_id;
int p_price;
};
product Structure Variable Declaration
struct product p1[100];
Declaring structure variable
Example (time Structure Definition)
struct time
{
int hour;
int min;
int sec;
};
time Structure Variable Declaration
struct time t1;
Accessing a structure members
• Each variable of structure has its own copy of
member variables.
• The member variables are accessed using the
dot (.) operator or member operator.
• Syntax:
structure_variable.member;
Accessing a structure members
Syntax: structure_variable.member;
Example (Student Structure Definition)
struct student
{ char name[20];
int roll_no;
int m1,m2,m3;
int tot;
float avg; };
Student Structure Variable Declaration
struct student s1;
Student Structure Accessing members
s1. name s1. m1 s1. m3 s1. avg
s1. rollno s1. m2 s1. tot
Accessing a structure members
Example (employee Structure Definition)
struct employee{ char name[20];
int e_id;
int sal; };
Employee Structure Variable Declaration)
struct employee e1,e2[10];
Employee Structure Accessing members
e1. name e1. sal e1. e_id
Employee Structure Accessing members –Array
e2[0]. name e2[0]. sal e2[0]. e_id
e2[1]. name e2[1]. sal e2[1]. e_id
Accessing a structure members
Example (product Structure Definition)
struct product{char prod_name[20];
int p_id;
int p_price; };
product Structure Variable Declaration
struct product p1[100];
product Structure Accessing members (Array)
p1[0]. prod_name e2[0]. p_id e2[0]. p_price
p1[1]. prod_name e2[1]. p_id e2[1]. p_price
p1[2]. prod_name e2[2]. p_id e2[2]. p_price
Question
Definition of a Structure for Time Given
Create variable for time and access the
members
struct time
{
int hour;
int min;
int sec;
};
Answer
Time Structure Variable Declaration
struct time t1;
Time Structure Accessing members
t1.hour
t1.min
t1.sec
Program to Read and Display Student
information
}Structure Definition
}Structure Declaration
}Structure Accessing Members
Student Total and Average
Program
Define a structure to store the student
details like name ,Roll no, marks in three
subjects, total and average. Read name
,Roll no, marks in three subjects fields and
write your logic to calculate the total and
average for n students and display rollno,
name, total and average.
Program
Define a structure to store the employee
details like name, employee id, salary.
Read name , employee id, basic pay fields
and write your logic to calculate the
salary(bp+hra+da+pf) of a employee and
display employee id, name, and salary.
Difference between Array and
Structure
Array Structure
Array is collection of homogeneous data. Structure is the collection of
heterogeneous data.
Array data are access using index. Structure elements are access using .
operator.
Difference between Structure and
Union
Union Structure
‘union’ is used to define a union ‘struct’ is used to describe a structure
Members share memory space Members share have individual memory
space
Size of a union is equal to that of the
largest member
The size of a structure is similar to the
total of the dimensions of all members

More Related Content

What's hot (20)

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...
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Structures,pointers and strings in c Programming
Structures,pointers and strings in c ProgrammingStructures,pointers and strings in c Programming
Structures,pointers and strings in c Programming
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Structure in C
Structure in CStructure in C
Structure in C
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
When to use a structure vs classes in c++
When to use a structure vs classes in c++When to use a structure vs classes in c++
When to use a structure vs classes in c++
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
C# program structure
C# program structureC# program structure
C# program structure
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
#Jai c presentation
#Jai c presentation#Jai c presentation
#Jai c presentation
 
Structures
StructuresStructures
Structures
 
Arrays
ArraysArrays
Arrays
 

Similar to Introduction to Structures in C

data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing conceptskavitham66441
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structuresKrishna Nanda
 
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.pdfsudhakargeruganti
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referentialbabuk110
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4YOGESH SINGH
 
Chapter15 structure
Chapter15 structureChapter15 structure
Chapter15 structureDeepak Singh
 
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).pdfHimanshuKansal22
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and StructuresGem WeBlog
 
Structure In C
Structure In CStructure In C
Structure In Cyndaravind
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxGebruGetachew2
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and PointersPrabu U
 
Str
StrStr
StrAcad
 

Similar to Introduction to Structures in C (20)

data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
C structure and union
C structure and unionC structure and union
C structure and union
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
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
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
1. structure
1. structure1. structure
1. structure
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
 
Chapter15 structure
Chapter15 structureChapter15 structure
Chapter15 structure
 
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
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Structure In C
Structure In CStructure In C
Structure In C
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
Structures and Unions
Structures and UnionsStructures and Unions
Structures and Unions
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
Str
StrStr
Str
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

Introduction to Structures in C

  • 2. Introduction to Structure Problem: – How to group together a collection of data items of different types that are logically related to a particular entity??? Example: Student Type which contains name, rollno, marks of six subjects, total, average. Solution: Structure
  • 3. Structure contd… • A structure is a collection of variables of different data types under a single name. • The variables are called members of the structure. • The structure is also called a user- defined data type.
  • 4. Structure • Definition • Declaration • Accessing a structure members • Structure initialization
  • 5. Defining a Structure • Syntax: struct structure_name { data_type member_variable1; data_type member_variable2; ………………………………; data_type member_variableN; };
  • 6. Example 1 Defining a Structure for Student struct student { char name[20]; int roll_no; int m1,m2,m3; int tot; float avg; };
  • 7. Example 2 Defining a Structure for Employee struct employee { char name[20]; int e_id; int sal; };
  • 8. Example 3 Defining a Structure for Product struct product { char prod_name[20]; int p_id; int p_price; };
  • 9. Example 4 Defining a Structure for Time struct time { int hour; int min; int sec; };
  • 10. Question Defining a Structure for Book • Create a Structure for book which contains book name, book issn number, price of the book, net quantity available Requirement Data Type book name String (array of characters) size=50 book issn number String (array of characters) size =10 price of the book int net quantity available int
  • 11. Answer Defining a Structure for Book struct book { char b_name[50]; char ssn_no[50]; int price; int quanity; };
  • 12. Declaring structure variable Syntax: struct structure_name structure_variable; Example (Student Structure Definition) struct student { char name[20]; int roll_no; int m1,m2,m3; int tot; float avg; }; Student Structure Variable Declaration struct student s1;
  • 13. Declaring structure variable Example (employee Structure Definition) struct employee { char name[20]; int e_id; int sal; }; Employee Structure Variable Declaration struct employee e1,e2[10];
  • 14. Declaring structure variable Example (product Structure Definition) struct product { char prod_name[20]; int p_id; int p_price; }; product Structure Variable Declaration struct product p1[100];
  • 15. Declaring structure variable Example (time Structure Definition) struct time { int hour; int min; int sec; }; time Structure Variable Declaration struct time t1;
  • 16. Accessing a structure members • Each variable of structure has its own copy of member variables. • The member variables are accessed using the dot (.) operator or member operator. • Syntax: structure_variable.member;
  • 17. Accessing a structure members Syntax: structure_variable.member; Example (Student Structure Definition) struct student { char name[20]; int roll_no; int m1,m2,m3; int tot; float avg; }; Student Structure Variable Declaration struct student s1; Student Structure Accessing members s1. name s1. m1 s1. m3 s1. avg s1. rollno s1. m2 s1. tot
  • 18. Accessing a structure members Example (employee Structure Definition) struct employee{ char name[20]; int e_id; int sal; }; Employee Structure Variable Declaration) struct employee e1,e2[10]; Employee Structure Accessing members e1. name e1. sal e1. e_id Employee Structure Accessing members –Array e2[0]. name e2[0]. sal e2[0]. e_id e2[1]. name e2[1]. sal e2[1]. e_id
  • 19. Accessing a structure members Example (product Structure Definition) struct product{char prod_name[20]; int p_id; int p_price; }; product Structure Variable Declaration struct product p1[100]; product Structure Accessing members (Array) p1[0]. prod_name e2[0]. p_id e2[0]. p_price p1[1]. prod_name e2[1]. p_id e2[1]. p_price p1[2]. prod_name e2[2]. p_id e2[2]. p_price
  • 20. Question Definition of a Structure for Time Given Create variable for time and access the members struct time { int hour; int min; int sec; };
  • 21. Answer Time Structure Variable Declaration struct time t1; Time Structure Accessing members t1.hour t1.min t1.sec
  • 22. Program to Read and Display Student information }Structure Definition }Structure Declaration }Structure Accessing Members
  • 23. Student Total and Average
  • 24. Program Define a structure to store the student details like name ,Roll no, marks in three subjects, total and average. Read name ,Roll no, marks in three subjects fields and write your logic to calculate the total and average for n students and display rollno, name, total and average.
  • 25.
  • 26. Program Define a structure to store the employee details like name, employee id, salary. Read name , employee id, basic pay fields and write your logic to calculate the salary(bp+hra+da+pf) of a employee and display employee id, name, and salary.
  • 27.
  • 28. Difference between Array and Structure Array Structure Array is collection of homogeneous data. Structure is the collection of heterogeneous data. Array data are access using index. Structure elements are access using . operator.
  • 29. Difference between Structure and Union Union Structure ‘union’ is used to define a union ‘struct’ is used to describe a structure Members share memory space Members share have individual memory space Size of a union is equal to that of the largest member The size of a structure is similar to the total of the dimensions of all members