SlideShare a Scribd company logo
PROGRAMMING IN 
C
CONTENTS 
STRUCTURE 
UNION
STRUCTURE 
Structure is user define data type. When we defined a 
structure as a group of elements of different data-type 
held together in a single unit .The individual 
elements are called data members of Structure. 
Members of the structure can be accessed & 
processed separately. The graphical representation 
of a structure is : 
Structure name 
Member-1 
Member-2 
Member-3 
Member-n
Syntax : 
struct name 
{ 
data-type member-1; 
data-type member-2; 
data-type member-3; 
----------------------------- 
----------------------------- 
data-type member-n; 
}
ACCESSING MEMBERS OF STRUCTURE 
The members of a structure variable are accessed using dot 
operator(.). The syntax is 
structure-variable. member name 
Example: struct date 
{ 
int dd; 
int mm; 
int yy; 
} 
dob; 
The values to members of structure variable dob are assigned 
as: 
dob.dd=05; 
dob.mm=07; 
dob.yy=2014;
INITIALIZATION OF STRUCTURES 
Like variables of other data types, a structure 
variable can be initialized. For illustration consider 
the following segment. 
struct std 
{ 
int rollno; 
char name[25]; 
char Dept[25]; 
}; 
struct std student={44,”Divesh”,”IT”};
FUNCTIONS & STRUCTURES 
In C ,structure can be passed to a function as 
a single variable. The scope of a structure 
declaration should be an external storage 
class whenever a function in the main 
program is using a structure data type. The 
member data should be same throughout the 
program. Individual structure members can 
be passed to a function as arguments in the 
function call & a single structure member can 
be returned through the return statement.
POINTER & STRUCTURE 
Through the use of (&) address operator, starting 
address of a structure can be accessed in the 
same manner as any other address. Therefore, if 
variable represents a structure type variable the 
& variable represents the beginning address of 
that variable. A pointer variable for a structure 
declare as : 
type *ptr 
to assign the starting address of a structure 
variable to pointer as 
ptr=&variable
Example: 
struct 
{ 
int acc_no; 
char acc_type; 
char customer[50]; 
float bal_amount; 
} 
s_customer,*ptr_cust; 
Pointer structure can be accessed & processed in 
following way: 
(*structure_name).field name_variable;
ARRAY OF STRUCTURES 
When we want to process a list of 
values of structure type, it is 
required to use an array of 
structures. The array of structures 
are defined as simple structures, 
only the difference is that instead 
of a simple variable, we specify 
array variable name for structure.
Example: 
struct stud 
{ 
int rollno; 
char name[25]; 
char dept[25]; 
int height; 
}; 
struct stud student[100];
NESTED STRUCTURES 
A structure can be embedded in another structure. The concept 
of nested structure illustrated by following example: 
struct name 
{ 
char fname[20]; 
char mname[20]; 
}; 
struct sal 
{ 
char empno[5]; 
char dept[15]; 
float salary; 
} 
employee;
UNION 
Union is quite similar to structure but processing & storage 
is little different. Both contains a group of members 
which may be off different data types but in structure 
each member has its own memory location, whereas in 
union all the members share the same storage area. 
Syntax- Union tag-name 
{ 
data-type member1; 
data-type member 2; 
----------------------------- 
data-type member n; 
};
DIFFERENCE 
Structure Union 
Structure allocates storage space for 
all its members separately. 
Union allocates one common storage 
space for all its members. 
Union finds that which of its member 
needs high storage space over other 
members and allocates that much space 
Structure occupies higher memory 
space. 
Union occupies lower memory space 
over structure. 
We can access all members of structure 
at a time. 
We can access only one member of 
union at a time. 
All members may be initialized. Only first member may be initialized. 
Consume more space than union. Conservation of memory is possible. 
Syntax: struct name 
{ 
data-type member-1; 
data-type member-2; 
---------------------- 
data-type member-n; 
} 
Syntax: Union tag-name 
{ 
data-type member1; 
data-type member 2; 
------------------------- 
data-type member n; 
}
Ad

More Related Content

What's hot (20)

Pointer in c
Pointer in cPointer in c
Pointer in c
Imamul Kadir
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
C Pointers
C PointersC Pointers
C Pointers
omukhtar
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
Neel Mungra
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
sudhakargeruganti
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
gourav kottawar
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
Md. Afif Al Mamun
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
Saket Pathak
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
minal kumar soni
 
pointers
pointerspointers
pointers
teach4uin
 
Typedef
TypedefTypedef
Typedef
vaseemkhn
 
Pointers in c
Pointers in cPointers in c
Pointers in c
CHANDAN KUMAR
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
Mutable and immutable classes
Mutable and  immutable classesMutable and  immutable classes
Mutable and immutable classes
Tech_MX
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
Sharad Dubey
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
C Pointers
C PointersC Pointers
C Pointers
omukhtar
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
sudhakargeruganti
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
gourav kottawar
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
Mutable and immutable classes
Mutable and  immutable classesMutable and  immutable classes
Mutable and immutable classes
Tech_MX
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 

Similar to Programming in C session 3 (20)

Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
Sowri Rajan
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
Abhishekkumarsingh630054
 
Str
StrStr
Str
Acad
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
patcha535
 
Structure In C
Structure In CStructure In C
Structure In C
yndaravind
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
Dhrumil Patel
 
#Jai c presentation
#Jai c presentation#Jai c presentation
#Jai c presentation
JAI BAMORIYA
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
Ananthi Palanisamy
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
Acad
 
PPS 8.8.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.)
PPS 8.8.BASIC ALGORITHMS  SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.)PPS 8.8.BASIC ALGORITHMS  SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.)
PPS 8.8.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.)
Sitamarhi Institute of Technology
 
C structure and union
C structure and unionC structure and union
C structure and union
Thesis Scientist Private Limited
 
Structures
StructuresStructures
Structures
Praveen M Jigajinni
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
Ram Sagar Mourya
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
kavitham66441
 
Structure c
Structure cStructure c
Structure c
thirumalaikumar3
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
Tanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdfStructure and Union (Self Study).pdfStructure and Union (Self Study).pdf
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
monimhossain14
 
UNIONS.pptx
UNIONS.pptxUNIONS.pptx
UNIONS.pptx
Villa College-Republic of Maldives
 
Ad

Recently uploaded (20)

How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Ad

Programming in C session 3

  • 3. STRUCTURE Structure is user define data type. When we defined a structure as a group of elements of different data-type held together in a single unit .The individual elements are called data members of Structure. Members of the structure can be accessed & processed separately. The graphical representation of a structure is : Structure name Member-1 Member-2 Member-3 Member-n
  • 4. Syntax : struct name { data-type member-1; data-type member-2; data-type member-3; ----------------------------- ----------------------------- data-type member-n; }
  • 5. ACCESSING MEMBERS OF STRUCTURE The members of a structure variable are accessed using dot operator(.). The syntax is structure-variable. member name Example: struct date { int dd; int mm; int yy; } dob; The values to members of structure variable dob are assigned as: dob.dd=05; dob.mm=07; dob.yy=2014;
  • 6. INITIALIZATION OF STRUCTURES Like variables of other data types, a structure variable can be initialized. For illustration consider the following segment. struct std { int rollno; char name[25]; char Dept[25]; }; struct std student={44,”Divesh”,”IT”};
  • 7. FUNCTIONS & STRUCTURES In C ,structure can be passed to a function as a single variable. The scope of a structure declaration should be an external storage class whenever a function in the main program is using a structure data type. The member data should be same throughout the program. Individual structure members can be passed to a function as arguments in the function call & a single structure member can be returned through the return statement.
  • 8. POINTER & STRUCTURE Through the use of (&) address operator, starting address of a structure can be accessed in the same manner as any other address. Therefore, if variable represents a structure type variable the & variable represents the beginning address of that variable. A pointer variable for a structure declare as : type *ptr to assign the starting address of a structure variable to pointer as ptr=&variable
  • 9. Example: struct { int acc_no; char acc_type; char customer[50]; float bal_amount; } s_customer,*ptr_cust; Pointer structure can be accessed & processed in following way: (*structure_name).field name_variable;
  • 10. ARRAY OF STRUCTURES When we want to process a list of values of structure type, it is required to use an array of structures. The array of structures are defined as simple structures, only the difference is that instead of a simple variable, we specify array variable name for structure.
  • 11. Example: struct stud { int rollno; char name[25]; char dept[25]; int height; }; struct stud student[100];
  • 12. NESTED STRUCTURES A structure can be embedded in another structure. The concept of nested structure illustrated by following example: struct name { char fname[20]; char mname[20]; }; struct sal { char empno[5]; char dept[15]; float salary; } employee;
  • 13. UNION Union is quite similar to structure but processing & storage is little different. Both contains a group of members which may be off different data types but in structure each member has its own memory location, whereas in union all the members share the same storage area. Syntax- Union tag-name { data-type member1; data-type member 2; ----------------------------- data-type member n; };
  • 14. DIFFERENCE Structure Union Structure allocates storage space for all its members separately. Union allocates one common storage space for all its members. Union finds that which of its member needs high storage space over other members and allocates that much space Structure occupies higher memory space. Union occupies lower memory space over structure. We can access all members of structure at a time. We can access only one member of union at a time. All members may be initialized. Only first member may be initialized. Consume more space than union. Conservation of memory is possible. Syntax: struct name { data-type member-1; data-type member-2; ---------------------- data-type member-n; } Syntax: Union tag-name { data-type member1; data-type member 2; ------------------------- data-type member n; }

Editor's Notes

  • #2: By prerna sharma