SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
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 (20)

PPTX
Structure in C language
CGC Technical campus,Mohali
 
PPTX
Pointers in c language
Tanmay Modi
 
PPTX
Pointer in c
lavanya marichamy
 
PPTX
Dynamic memory allocation in c
lavanya marichamy
 
PPTX
data types in C programming
Harshita Yadav
 
PPT
Pointers C programming
Appili Vamsi Krishna
 
PPT
Function overloading(c++)
Ritika Sharma
 
PPT
Variables in C Programming
programming9
 
PPTX
Arrays in c
Jeeva Nanthini
 
PPTX
Pointers in c++
sai tarlekar
 
PPTX
Array Of Pointers
Sharad Dubey
 
PPTX
Arrays in c
CHANDAN KUMAR
 
PPTX
Pointers in c++
Vineeta Garg
 
PPTX
C Structures and Unions
Dhrumil Patel
 
PPTX
C programing -Structure
shaibal sharif
 
PDF
Pointers and call by value, reference, address in C
Syed Mustafa
 
PPTX
Presentation on pointer.
Md. Afif Al Mamun
 
PPT
structure and union
student
 
PPTX
Functions in C
Kamal Acharya
 
PPTX
Union in C programming
Kamal Acharya
 
Structure in C language
CGC Technical campus,Mohali
 
Pointers in c language
Tanmay Modi
 
Pointer in c
lavanya marichamy
 
Dynamic memory allocation in c
lavanya marichamy
 
data types in C programming
Harshita Yadav
 
Pointers C programming
Appili Vamsi Krishna
 
Function overloading(c++)
Ritika Sharma
 
Variables in C Programming
programming9
 
Arrays in c
Jeeva Nanthini
 
Pointers in c++
sai tarlekar
 
Array Of Pointers
Sharad Dubey
 
Arrays in c
CHANDAN KUMAR
 
Pointers in c++
Vineeta Garg
 
C Structures and Unions
Dhrumil Patel
 
C programing -Structure
shaibal sharif
 
Pointers and call by value, reference, address in C
Syed Mustafa
 
Presentation on pointer.
Md. Afif Al Mamun
 
structure and union
student
 
Functions in C
Kamal Acharya
 
Union in C programming
Kamal Acharya
 

Similar to Structures in c language (20)

PPTX
Computer science ( Structures In C ) Ppt
SobhitRanjanPanda
 
PPTX
Structure prespentation
ashu awais
 
PDF
structure and union1.pdf
HMCollegeInfo
 
PDF
fundamental programming languagech#2 (3).pdf
gemchisgetahun
 
PDF
Structures in c++
Swarup Boro
 
PDF
Structures in c++
Swarup Kumar Boro
 
PPTX
CPU : Structures And Unions
Dhrumil Patel
 
PPTX
Structure in c language
sangrampatil81
 
PDF
Lk module4 structures
Krishna Nanda
 
PPTX
Programming in C
MalathiNagarajan20
 
PDF
Chapter 13.1.9
patcha535
 
PDF
Unit 4 qba
Sowri Rajan
 
PPTX
Structure.pptx
MohammedOmer401579
 
PPT
2 lesson 2 object oriented programming in c++
Jeff TUYISHIME
 
PPTX
oop Lecture 1
Atif Khan
 
PPTX
Unit-V.pptx
Mehul Desai
 
PDF
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
PPTX
Definition, Declaration of Structures in C.pptx
AnithaTAssistantProf
 
PPT
Lecture number three Structures (1).ppt
shahbazqadeer1
 
DOCX
Str
Acad
 
Computer science ( Structures In C ) Ppt
SobhitRanjanPanda
 
Structure prespentation
ashu awais
 
structure and union1.pdf
HMCollegeInfo
 
fundamental programming languagech#2 (3).pdf
gemchisgetahun
 
Structures in c++
Swarup Boro
 
Structures in c++
Swarup Kumar Boro
 
CPU : Structures And Unions
Dhrumil Patel
 
Structure in c language
sangrampatil81
 
Lk module4 structures
Krishna Nanda
 
Programming in C
MalathiNagarajan20
 
Chapter 13.1.9
patcha535
 
Unit 4 qba
Sowri Rajan
 
Structure.pptx
MohammedOmer401579
 
2 lesson 2 object oriented programming in c++
Jeff TUYISHIME
 
oop Lecture 1
Atif Khan
 
Unit-V.pptx
Mehul Desai
 
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Definition, Declaration of Structures in C.pptx
AnithaTAssistantProf
 
Lecture number three Structures (1).ppt
shahbazqadeer1
 
Str
Acad
 
Ad

More from tanmaymodi4 (10)

PDF
Cryptocurrency
tanmaymodi4
 
PPTX
Pointers in c v5 12102017 1
tanmaymodi4
 
PPTX
Operators and expressions in c language
tanmaymodi4
 
PPTX
Loops in c language
tanmaymodi4
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
Dynamic memory allocation in c language
tanmaymodi4
 
PPTX
Arrays in c language
tanmaymodi4
 
PPTX
Decision statements in c language
tanmaymodi4
 
PPTX
Preprocessor directives in c language
tanmaymodi4
 
PPTX
Storage classes in c language
tanmaymodi4
 
Cryptocurrency
tanmaymodi4
 
Pointers in c v5 12102017 1
tanmaymodi4
 
Operators and expressions in c language
tanmaymodi4
 
Loops in c language
tanmaymodi4
 
Functions in c language
tanmaymodi4
 
Dynamic memory allocation in c language
tanmaymodi4
 
Arrays in c language
tanmaymodi4
 
Decision statements in c language
tanmaymodi4
 
Preprocessor directives in c language
tanmaymodi4
 
Storage classes in c language
tanmaymodi4
 
Ad

Recently uploaded (20)

PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 

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: