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

More Related Content

What's hot

C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
shaibal sharif
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Structure c
Structure cStructure c
Structure c
thirumalaikumar3
 
Array and string
Array and stringArray and string
Array and string
prashant chelani
 
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
kashyap399
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
C tokens
C tokensC tokens
C tokens
Manu1325
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
arushi bhatnagar
 

What's hot (20)

C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Data types in C
Data types in CData types in C
Data types in C
 
Structure c
Structure cStructure c
Structure c
 
Array and string
Array and stringArray and string
Array and string
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
structure and union
structure and unionstructure and union
structure and union
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Array in c
Array in cArray in c
Array in c
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
C tokens
C tokensC tokens
C tokens
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 

Similar to 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.pdf
HMCollegeInfo
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
Swarup Boro
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
Dhrumil Patel
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
Krishna Nanda
 
Programming in C
Programming in CProgramming in C
Programming in C
MalathiNagarajan20
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
MohammedOmer401579
 
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 1
Atif Khan
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
Mehul Desai
 
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
SowmyaJyothi3
 
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
AnithaTAssistantProf
 
Str
StrStr
Str
Acad
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
Acad
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
WondimuBantihun1
 

Similar to 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++
 
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
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 

More from tanmaymodi4

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

More from 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
 

Recently uploaded

Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 

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: