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

Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
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.pptxheathfieldcps1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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.pdfPoh-Sun Goh
 
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.pdfNirmal Dwivedi
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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
 
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
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

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