SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Structures in C
Definition
 Structure is a user-defined data type
in C which allows you to combine
different data types to store a
particular type of record.
 It is somewhat similar to an Array. The
only difference is that array is used to
store collection of similar data types
while structure can store collection of
any type of data.
Example:
Structure is used to represent a record.
 Suppose you want to store record
of Student which consists of student
name, address, roll number and age. You
can define a structure to hold this
information.
 Suppose you want to keep track of your
books in a library. You might want to track
the following attributes about each book −
 Title
 Author
 Subject
 Book ID
Defining a structure
 struct keyword is used to define a structure.
 struct defines a new data type which is a
collection of different types of data.
 Syntax :
 Note: The closing braces in the structure type
declaration must be followed by a
semicolon(;).
Example of Structure
•Here the struct Book declares a structure to hold the
details of book which consists of three data fields,
namely name, price and pages.
•These fields are called structure elements or
members.
•Each member can have different data type,like in this
case, name is of char type and price is of int type etc.
•Book is the name of the structure and is called structure
Declaring Structure Variables
 It is possible to declare variables of
a structure, after the structure is
defined.
 Structure variable declaration is
similar to the declaration of variables
of any other data types.
 Structure variables can be declared in
following two ways.
1) Declaring Structure variables
separately
2) Declaring Structure Variables with
Structure definition
Accessing Structure Members
 Structure members can be accessed
and assigned values in number of ways.
 Structure member has no meaning
independently.
 In order to assign a value to a structure
member, the member name must be
linked with the structure variable using
dot . operator also called period
or member access operator.
We can also use scanf() to give values
to structure members through
terminal.
Structure Initialization
 Like any other data type, structure
variable can also be initialized at
compile time.
Or
Array of Structure
 We can also declare an array of structure.
Each element of the array represents a
structure variable.
 Example : struct employee emp[5];
The below code define an array emp of size 5 elements. Each
element of array emp is of type employee
Nested Structures
 Nesting of structures, is also permitted
in C language.
 Example :
Structure as function arguments
 We can pass a structure as a function
argument in similar way as we pass any other
variable or array.
 Example:

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Functions in c language
Functions in c language Functions in c language
Functions in c language
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C string
C stringC string
C string
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Strings
StringsStrings
Strings
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Array in c++
Array in c++Array in c++
Array in c++
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
C pointer
C pointerC pointer
C pointer
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
C Pointers
C PointersC Pointers
C Pointers
 
Structure in C
Structure in CStructure in C
Structure in C
 

Ähnlich wie Structures in c language

Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation ashu awais
 
structure and union1.pdf
structure and union1.pdfstructure and union1.pdf
structure and union1.pdfHMCollegeInfo
 
Structures in c++
Structures in c++Structures in c++
Structures in c++Swarup Boro
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structureshaibal sharif
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And UnionsDhrumil Patel
 
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
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
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++Jeff TUYISHIME
 
oop Lecture 1
oop Lecture 1oop Lecture 1
oop Lecture 1Atif Khan
 
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
 
Definition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptxDefinition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptxAnithaTAssistantProf
 
Str
StrStr
StrAcad
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and TypedefAcad
 

Ähnlich wie Structures in c language (20)

Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
structure and union1.pdf
structure and union1.pdfstructure and union1.pdf
structure and union1.pdf
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
 
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++
 
oop Lecture 1
oop Lecture 1oop Lecture 1
oop Lecture 1
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
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
 
Definition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptxDefinition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptx
 
Str
StrStr
Str
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 

Mehr von tanmaymodi4

Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1tanmaymodi4
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c languagetanmaymodi4
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c languagetanmaymodi4
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 

Mehr von tanmaymodi4 (9)

Cryptocurrency
CryptocurrencyCryptocurrency
Cryptocurrency
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c language
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 

Kürzlich hochgeladen

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
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
 

Kürzlich hochgeladen (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
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...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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
 

Structures in c language

  • 2. Definition  Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record.  It is somewhat similar to an Array. The only difference is that array is used to store collection of similar data types while structure can store collection of any type of data.
  • 3. Example: Structure is used to represent a record.  Suppose you want to store record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.  Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book −  Title  Author  Subject  Book ID
  • 4. Defining a structure  struct keyword is used to define a structure.  struct defines a new data type which is a collection of different types of data.  Syntax :  Note: The closing braces in the structure type declaration must be followed by a semicolon(;).
  • 5. Example of Structure •Here the struct Book declares a structure to hold the details of book which consists of three data fields, namely name, price and pages. •These fields are called structure elements or members. •Each member can have different data type,like in this case, name is of char type and price is of int type etc. •Book is the name of the structure and is called structure
  • 6. Declaring Structure Variables  It is possible to declare variables of a structure, after the structure is defined.  Structure variable declaration is similar to the declaration of variables of any other data types.  Structure variables can be declared in following two ways.
  • 7. 1) Declaring Structure variables separately
  • 8. 2) Declaring Structure Variables with Structure definition
  • 9. Accessing Structure Members  Structure members can be accessed and assigned values in number of ways.  Structure member has no meaning independently.  In order to assign a value to a structure member, the member name must be linked with the structure variable using dot . operator also called period or member access operator.
  • 10. We can also use scanf() to give values to structure members through terminal.
  • 11. Structure Initialization  Like any other data type, structure variable can also be initialized at compile time. Or
  • 12. Array of Structure  We can also declare an array of structure. Each element of the array represents a structure variable.  Example : struct employee emp[5];
  • 13. The below code define an array emp of size 5 elements. Each element of array emp is of type employee
  • 14. Nested Structures  Nesting of structures, is also permitted in C language.  Example :
  • 15. Structure as function arguments  We can pass a structure as a function argument in similar way as we pass any other variable or array.  Example: