SlideShare a Scribd company logo
1 of 18
V.V. VANNIAPERUMAL COLLEGE FOR WOMEN
Programming in C
Structures
Dr. T. Anitha
Assistant Professor
Department of Mathematics(SF)
 int dynami;
 int trig;
 int c;
 float lab;
An array is a fixed-size sequenced collection of elements of same data type. ie., it
is a grouping of like-type. So in array a list of items can be given in one variable
name.
 The general form of array declaration is
type variable_name[size]
Examples:
 int dynami[50];
 int trig[50];
 int c[50];
 float lab[40];
Array
Example:
Suppose we have to store prices of three different items in four shops:
Item 1 Item 2 Item 3
Shop 1 310 275 365
Shop 2 210 190 325
Shop 3 405 225 240
Shop4 260 300 380
C allows as to define such tables of item in single variable using two-
dimensional arrays such as
p[4][3]
Two-dimensional array are declared as follows:
Type array_name[row_size][column_size]
Structure is a mechanism for packing data of different data
type. A structure is a convenient tool for handling a group of related
data item.
Example:
Using structure we can represent a set of attributes, such as
student_name, roll_number and marks.
Structures in C
struct book_bank
{
char title[20];
char author[15];
int page;
Float price;
};
Definition of Structures
The keyword struct declares a structure to hold the details of four
data field, namely title, author, pages and price, these fields are called
structure elements or members. Note that each member may belong to
different data types. book-bank is the name of the structure which called
structure tag.
struct tag_name
{
data_type member1;
data_type member2;
data_type member;
---------
};
The general format of structure definition
Declaring Structure Variables
After defining a structure we can declare variables of that type. A structure
variable declarations is similar to declaration of variables of any other data
types. It includes the following elements:
 The keyword strut
The structure tag name.
List of variable names separated by commas.
 A terminating semicolon.
Example:
struct book_bank, book1, book2, book3;
It declares book1, book2, book3 are variables of type struct book_bank.
Declaring Structure Variables
The complete variable definition and declaration is
struct book_bank
{
char title[20];
char author[15];
int page;
Float price;
};
struct book_bank, book1, book2, book3;
Declaring Structure Variables
It is also allowed to combine both variable definition and variable
declaration in one step as:
struct book_bank
{
char title[20];
char author[15];
int page;
float price;
} book1, book2, book3;
Access Structure Members
To access members of a structure, use the member operator dot
operator (.):
Example:
book1.price is the variable representing the price of book1 and it is treated
like any other ordinary variable.
Assigning values to the Structure variables
book.page=250;
book1.price=120.5
Strcpy(book1.title,”Algebra”);
Strcpy(book1.author, “Arumugam”);
Assigning values to the Structure variables
Reading data from keyboard
We can use scanf to give the values through the keyboard
Scanf(“%sn”,&book1.title);
Scanf(“%dn”, &book1.pages);
Example Program
struct personal
{
char name[20];
int day;
char month[10];
float salary;
};
main()
{
structure personal person;
printf(“Input Valuesn”);
scanf(“%s %d %s %f”, person.name,&person.day, &person.month,&person.salary);
printf(“Output Valuesn”);
printf (“%s %d %s %f”, person.name,person.day, person.month,person.salary);
}
Output:
Input Values
Rani 10 January 25000
Output Values
Rani 10 January 25000
THANK YOU

More Related Content

Similar to Definition, Declaration of Structures in C.pptx

Similar to Definition, Declaration of Structures in C.pptx (20)

Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
C UNIT-4 PREPARED BY M V BRAHMANANDA REC UNIT-4 PREPARED BY M V BRAHMANANDA RE
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
C structure and union
C structure and unionC structure and union
C structure and union
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
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
 
Structures in c programming
Structures in c programmingStructures in c programming
Structures in c programming
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
 
Programming in C
Programming in CProgramming in C
Programming in C
 

More from AnithaTAssistantProf

More from AnithaTAssistantProf (8)

Introduction to C Programming Language.pptx
Introduction to C Programming Language.pptxIntroduction to C Programming Language.pptx
Introduction to C Programming Language.pptx
 
Introduction of Differential Equation.pptx
Introduction of Differential Equation.pptxIntroduction of Differential Equation.pptx
Introduction of Differential Equation.pptx
 
Operational Research: LPP.pptx
Operational Research: LPP.pptxOperational Research: LPP.pptx
Operational Research: LPP.pptx
 
Permutation and combination-2.pptx
Permutation and combination-2.pptxPermutation and combination-2.pptx
Permutation and combination-2.pptx
 
Permutation and combinathion-1.pptx
Permutation and combinathion-1.pptxPermutation and combinathion-1.pptx
Permutation and combinathion-1.pptx
 
Odd man out.pptx
Odd man out.pptxOdd man out.pptx
Odd man out.pptx
 
Inventory Control File II.pptx
Inventory Control File II.pptxInventory Control File II.pptx
Inventory Control File II.pptx
 
Inventory control File I.pptx
Inventory control File I.pptxInventory control File I.pptx
Inventory control File I.pptx
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Definition, Declaration of Structures in C.pptx

  • 1. V.V. VANNIAPERUMAL COLLEGE FOR WOMEN Programming in C Structures Dr. T. Anitha Assistant Professor Department of Mathematics(SF)
  • 2.  int dynami;  int trig;  int c;  float lab;
  • 3. An array is a fixed-size sequenced collection of elements of same data type. ie., it is a grouping of like-type. So in array a list of items can be given in one variable name.  The general form of array declaration is type variable_name[size] Examples:  int dynami[50];  int trig[50];  int c[50];  float lab[40]; Array
  • 4. Example: Suppose we have to store prices of three different items in four shops: Item 1 Item 2 Item 3 Shop 1 310 275 365 Shop 2 210 190 325 Shop 3 405 225 240 Shop4 260 300 380
  • 5. C allows as to define such tables of item in single variable using two- dimensional arrays such as p[4][3] Two-dimensional array are declared as follows: Type array_name[row_size][column_size]
  • 6. Structure is a mechanism for packing data of different data type. A structure is a convenient tool for handling a group of related data item. Example: Using structure we can represent a set of attributes, such as student_name, roll_number and marks. Structures in C
  • 7. struct book_bank { char title[20]; char author[15]; int page; Float price; }; Definition of Structures
  • 8. The keyword struct declares a structure to hold the details of four data field, namely title, author, pages and price, these fields are called structure elements or members. Note that each member may belong to different data types. book-bank is the name of the structure which called structure tag.
  • 9. struct tag_name { data_type member1; data_type member2; data_type member; --------- }; The general format of structure definition
  • 10. Declaring Structure Variables After defining a structure we can declare variables of that type. A structure variable declarations is similar to declaration of variables of any other data types. It includes the following elements:  The keyword strut The structure tag name. List of variable names separated by commas.  A terminating semicolon. Example: struct book_bank, book1, book2, book3; It declares book1, book2, book3 are variables of type struct book_bank.
  • 11. Declaring Structure Variables The complete variable definition and declaration is struct book_bank { char title[20]; char author[15]; int page; Float price; }; struct book_bank, book1, book2, book3;
  • 12. Declaring Structure Variables It is also allowed to combine both variable definition and variable declaration in one step as: struct book_bank { char title[20]; char author[15]; int page; float price; } book1, book2, book3;
  • 13. Access Structure Members To access members of a structure, use the member operator dot operator (.): Example: book1.price is the variable representing the price of book1 and it is treated like any other ordinary variable.
  • 14. Assigning values to the Structure variables book.page=250; book1.price=120.5 Strcpy(book1.title,”Algebra”); Strcpy(book1.author, “Arumugam”);
  • 15. Assigning values to the Structure variables Reading data from keyboard We can use scanf to give the values through the keyboard Scanf(“%sn”,&book1.title); Scanf(“%dn”, &book1.pages);
  • 16. Example Program struct personal { char name[20]; int day; char month[10]; float salary; }; main() { structure personal person; printf(“Input Valuesn”); scanf(“%s %d %s %f”, person.name,&person.day, &person.month,&person.salary); printf(“Output Valuesn”); printf (“%s %d %s %f”, person.name,person.day, person.month,person.salary); }
  • 17. Output: Input Values Rani 10 January 25000 Output Values Rani 10 January 25000