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; 
}

More Related Content

What's hot (20)

PPT
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Jayanshu Gundaniya
 
PPTX
C++ Pointers
Chaand Sheikh
 
PDF
linked lists in data structures
DurgaDeviCbit
 
PPT
structure and union
student
 
PPTX
Structures in c language
tanmaymodi4
 
PPTX
Stream classes in C++
Shyam Gupta
 
PPT
Structure c
thirumalaikumar3
 
PPTX
C Structures and Unions
Dhrumil Patel
 
PPTX
C Programming: Structure and Union
Selvaraj Seerangan
 
PPT
Class and object in C++
rprajat007
 
PPT
Operators in C++
Sachin Sharma
 
PPTX
Pointers in c++
sai tarlekar
 
PPTX
Pointers in c++
Vineeta Garg
 
PPTX
INLINE FUNCTION IN C++
Vraj Patel
 
PPTX
DBMS: Types of keys
Bharati Ugale
 
PPTX
Operator overloading
Kumar
 
PPTX
Pointers in c language
Tanmay Modi
 
PPT
Pointers C programming
Appili Vamsi Krishna
 
PPTX
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
PPTX
Dynamic memory allocation in c++
Tech_MX
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Jayanshu Gundaniya
 
C++ Pointers
Chaand Sheikh
 
linked lists in data structures
DurgaDeviCbit
 
structure and union
student
 
Structures in c language
tanmaymodi4
 
Stream classes in C++
Shyam Gupta
 
Structure c
thirumalaikumar3
 
C Structures and Unions
Dhrumil Patel
 
C Programming: Structure and Union
Selvaraj Seerangan
 
Class and object in C++
rprajat007
 
Operators in C++
Sachin Sharma
 
Pointers in c++
sai tarlekar
 
Pointers in c++
Vineeta Garg
 
INLINE FUNCTION IN C++
Vraj Patel
 
DBMS: Types of keys
Bharati Ugale
 
Operator overloading
Kumar
 
Pointers in c language
Tanmay Modi
 
Pointers C programming
Appili Vamsi Krishna
 
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Dynamic memory allocation in c++
Tech_MX
 

Similar to Programming in C session 3 (20)

DOC
Unit 5 (1)
psaravanan1985
 
PPT
structure and union from C programming Language
AvrajeetGhosh
 
PPT
structure and union from c programming language.ppt
AvrajeetGhosh
 
PPTX
Module 5-Structure and Union
nikshaikh786
 
PPTX
Unit 9. Structure and Unions
Ashim Lamichhane
 
PDF
Chapter 13.1.9
patcha535
 
PDF
PROBLEM SOLVING USING C PPSC- UNIT -5.pdf
JNTUK KAKINADA
 
DOCX
C programming structures & union
Bathshebaparimala
 
DOCX
PPS 8.8.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.)
Sitamarhi Institute of Technology
 
PPTX
detail structure presentation of problem solving
talencorconsultancy
 
PDF
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
monimhossain14
 
DOCX
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
Rajeshkumar Reddy
 
PPTX
Structure & Union in C++
Davinder Kaur
 
PPTX
Chapter 8 Structure Part 2 (1).pptx
Abhishekkumarsingh630054
 
PPTX
Structure prespentation
ashu awais
 
PDF
slideset 7 structure and union (1).pdf
HimanshuKansal22
 
PPTX
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
PPTX
Programming for problem solving-II(UNIT-2).pptx
prathima304
 
PDF
03 structures
Rajan Gautam
 
PPTX
User defined data types.pptx
Ananthi Palanisamy
 
Unit 5 (1)
psaravanan1985
 
structure and union from C programming Language
AvrajeetGhosh
 
structure and union from c programming language.ppt
AvrajeetGhosh
 
Module 5-Structure and Union
nikshaikh786
 
Unit 9. Structure and Unions
Ashim Lamichhane
 
Chapter 13.1.9
patcha535
 
PROBLEM SOLVING USING C PPSC- UNIT -5.pdf
JNTUK KAKINADA
 
C programming structures & union
Bathshebaparimala
 
PPS 8.8.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.)
Sitamarhi Institute of Technology
 
detail structure presentation of problem solving
talencorconsultancy
 
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
monimhossain14
 
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
Rajeshkumar Reddy
 
Structure & Union in C++
Davinder Kaur
 
Chapter 8 Structure Part 2 (1).pptx
Abhishekkumarsingh630054
 
Structure prespentation
ashu awais
 
slideset 7 structure and union (1).pdf
HimanshuKansal22
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Smit Shah
 
Programming for problem solving-II(UNIT-2).pptx
prathima304
 
03 structures
Rajan Gautam
 
User defined data types.pptx
Ananthi Palanisamy
 
Ad

Recently uploaded (20)

PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
community health nursing question paper 2.pdf
Prince kumar
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
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