SlideShare a Scribd company logo
4
Most read
5
Most read
6
Most read
RAVI SHANKAR
B.TECH CSE 2ND YEAR
4915123
UNION
Union Data Type
A union is a user defined data type like structure.
The union groups logically related variables into a
single unit. The union data type allocate the space
equal to space need to hold the largest data
member of union. The union allows different types
of variable to share same space in memory. There is
no other difference between structure and union
than internal difference. The method to declare,
use and access the union is same as structure.
Defining of Union
A union has to defined, before it can used. The
syntax of defining a structure is
union <union_name>
{
<data_type> <variable_name>;
<data_type> <variable_name>;
……..
<data_type> <variable_name>;
};
Example of Union
The union of Employee is declared as
union employee
{
int emp_id;
char name[20];
float salary;
char address[50];
int dept_no;
int age;
};
Memory Space Allocation
8000
emp_id, dept_no, age
8002
salary
8004
name
8022
address
8050
employee
Difference between Structures & Union
1)The memory occupied by structure variable is
the sum of sizes of all the members but
memory occupied by union variable is equal to
space hold by the largest data member of a
union.
2)In the structure all the members are accessed
at any point of time but in union only one of
union member can be accessed at any given
time.
Application of Structures
Structure is used in database management to
maintain data about books in library, items in
store, employees in an organization, financial
accounting transaction in company. Beside that
other application are
1)Changing the size of cursor.
2)Clearing the contents of screen.
3)Drawing any graphics shape on screen.
4)Receiving the key from the keyboard.
Summary
• The member of structure variable is accessed by
pointer variable with arrow operator ().
• The structure variable can be passed to a function
as a parameter.
• The function can return a variable of structure
type.
• A union is like structure that group logically
related variables into a single unit. The union
allocate the space equal to space need to hold the
largest data member of union.
• Structure used in database management and
many more applications.
Thanks
Thanks

More Related Content

What's hot (20)

PPTX
C Programming: Structure and Union
Selvaraj Seerangan
 
PPTX
Pure virtual function and abstract class
Amit Trivedi
 
PPTX
Abstract class in c++
Sujan Mia
 
PPTX
Templates in c++
ThamizhselviKrishnam
 
ODP
C union
muhammadsarab
 
PPTX
Python Data-Types
Akhil Kaushik
 
PPTX
Constructor and Types of Constructors
Dhrumil Panchal
 
PDF
Constructors and Destructors
Dr Sukhpal Singh Gill
 
PDF
Constructors and destructors
Nilesh Dalvi
 
PPTX
Array in c programming
Mazharul Islam
 
PDF
Classes and objects
Nilesh Dalvi
 
PPTX
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
PPTX
Data types in C language
kashyap399
 
PPTX
Constructors in C++
RubaNagarajan
 
PDF
Managing I/O in c++
Pranali Chaudhari
 
PPTX
Nested queries in database
Satya P. Joshi
 
PPTX
INLINE FUNCTION IN C++
Vraj Patel
 
PPT
Inheritance C#
Raghuveer Guthikonda
 
PPTX
virtual function
VENNILAV6
 
PPT
C Structures And Unions
Ram Sagar Mourya
 
C Programming: Structure and Union
Selvaraj Seerangan
 
Pure virtual function and abstract class
Amit Trivedi
 
Abstract class in c++
Sujan Mia
 
Templates in c++
ThamizhselviKrishnam
 
C union
muhammadsarab
 
Python Data-Types
Akhil Kaushik
 
Constructor and Types of Constructors
Dhrumil Panchal
 
Constructors and Destructors
Dr Sukhpal Singh Gill
 
Constructors and destructors
Nilesh Dalvi
 
Array in c programming
Mazharul Islam
 
Classes and objects
Nilesh Dalvi
 
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
Data types in C language
kashyap399
 
Constructors in C++
RubaNagarajan
 
Managing I/O in c++
Pranali Chaudhari
 
Nested queries in database
Satya P. Joshi
 
INLINE FUNCTION IN C++
Vraj Patel
 
Inheritance C#
Raghuveer Guthikonda
 
virtual function
VENNILAV6
 
C Structures And Unions
Ram Sagar Mourya
 

Similar to Union In language C (20)

PPTX
Unit_6StructureandUnionpptx__2023_01_04_16_48_56.pptx
vekariyakashyap
 
PPTX
Unit6STRUCTUREANDUNIONpptx__2024_11_18_12_20_46.pptx
GImpact
 
PPSX
Union
Frijo Francis
 
PPTX
Structure & Union in C++
Davinder Kaur
 
PPTX
Programming in C session 3
Prerna Sharma
 
PPTX
STRUCTURES_UNION.pptx
727822TUCS116MOHANKU
 
PPTX
UNION 1.pptx
FarhanAbdullah29
 
PDF
slideset 7 structure and union (1).pdf
HimanshuKansal22
 
PPT
structure and union from C programming Language
AvrajeetGhosh
 
PPT
structure and union from c programming language.ppt
AvrajeetGhosh
 
PPT
Union.ppt
SureshM228
 
DOCX
Union from C and Data Strutures
Acad
 
PDF
Lecture19 unionsin c.ppt
eShikshak
 
PDF
C- language Lecture 7
Hatem Abd El-Salam
 
PPT
Session 6
Shailendra Mathur
 
PDF
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
monimhossain14
 
PPT
Lecture 19 - Struct and Union
Md. Imran Hossain Showrov
 
DOC
Unit 5 (1)
psaravanan1985
 
PPT
Structure c
thirumalaikumar3
 
Unit_6StructureandUnionpptx__2023_01_04_16_48_56.pptx
vekariyakashyap
 
Unit6STRUCTUREANDUNIONpptx__2024_11_18_12_20_46.pptx
GImpact
 
Structure & Union in C++
Davinder Kaur
 
Programming in C session 3
Prerna Sharma
 
STRUCTURES_UNION.pptx
727822TUCS116MOHANKU
 
UNION 1.pptx
FarhanAbdullah29
 
slideset 7 structure and union (1).pdf
HimanshuKansal22
 
structure and union from C programming Language
AvrajeetGhosh
 
structure and union from c programming language.ppt
AvrajeetGhosh
 
Union.ppt
SureshM228
 
Union from C and Data Strutures
Acad
 
Lecture19 unionsin c.ppt
eShikshak
 
C- language Lecture 7
Hatem Abd El-Salam
 
Structure and Union (Self Study).pdfStructure and Union (Self Study).pdf
monimhossain14
 
Lecture 19 - Struct and Union
Md. Imran Hossain Showrov
 
Unit 5 (1)
psaravanan1985
 
Structure c
thirumalaikumar3
 
Ad

Recently uploaded (20)

PPT
Brief History of Python by Learning Python in three hours
adanechb21
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
PDF
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
Why Are More Businesses Choosing Partners Over Freelancers for Salesforce.pdf
Cymetrix Software
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
PDF
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
What companies do with Pharo (ESUG 2025)
ESUG
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
Brief History of Python by Learning Python in three hours
adanechb21
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
Activate_Methodology_Summary presentatio
annapureddyn
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Why Are More Businesses Choosing Partners Over Freelancers for Salesforce.pdf
Cymetrix Software
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
What companies do with Pharo (ESUG 2025)
ESUG
 
Presentation about variables and constant.pptx
kr2589474
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
Ad

Union In language C

  • 1. RAVI SHANKAR B.TECH CSE 2ND YEAR 4915123 UNION
  • 2. Union Data Type A union is a user defined data type like structure. The union groups logically related variables into a single unit. The union data type allocate the space equal to space need to hold the largest data member of union. The union allows different types of variable to share same space in memory. There is no other difference between structure and union than internal difference. The method to declare, use and access the union is same as structure.
  • 3. Defining of Union A union has to defined, before it can used. The syntax of defining a structure is union <union_name> { <data_type> <variable_name>; <data_type> <variable_name>; …….. <data_type> <variable_name>; };
  • 4. Example of Union The union of Employee is declared as union employee { int emp_id; char name[20]; float salary; char address[50]; int dept_no; int age; };
  • 5. Memory Space Allocation 8000 emp_id, dept_no, age 8002 salary 8004 name 8022 address 8050 employee
  • 6. Difference between Structures & Union 1)The memory occupied by structure variable is the sum of sizes of all the members but memory occupied by union variable is equal to space hold by the largest data member of a union. 2)In the structure all the members are accessed at any point of time but in union only one of union member can be accessed at any given time.
  • 7. Application of Structures Structure is used in database management to maintain data about books in library, items in store, employees in an organization, financial accounting transaction in company. Beside that other application are 1)Changing the size of cursor. 2)Clearing the contents of screen. 3)Drawing any graphics shape on screen. 4)Receiving the key from the keyboard.
  • 8. Summary • The member of structure variable is accessed by pointer variable with arrow operator (). • The structure variable can be passed to a function as a parameter. • The function can return a variable of structure type. • A union is like structure that group logically related variables into a single unit. The union allocate the space equal to space need to hold the largest data member of union. • Structure used in database management and many more applications.