SlideShare a Scribd company logo
1 of 39
Structure & Union
Content
• Introduction
• Structure Definition
• Accessing Structure Member
• Array of Structure
• Pointer to Structure
• Function and Structure
• Union
Introduction
• User defined data type
• Collection of heterogeneous data
• Referred by a common name
• A function can return a structure
Definition
• Collection of logically related data with same
or different data-type, the logically related
data are grouped together in a common
name.
• Structure Tag
• Data Member or Fields
Syntax
• struct tag_name
{
data-type Field1;
data-type Field2;
………
};
Example
• struct book
{
char name[20];
char author[10];
int pages;
float price;
} ;
Declaration of Variable
• struct student
{
int roll_no;
char name[20];
float marks;
} s1,*s2;
Using Structure Tag
• struct struct_tag variable-list;
• struct student s1,*s2;
• Variable can be declared inside(local) or
outside(global) of main function
Memory Allocation
• struct student s1 = {1,”Rupesh”,67.67};
• N=sizeof(s1);
• N ????
s1.roll_no s1.name s1.marks
1 R u p e s h

0
G V 67.67
6502 6504 6024 6025
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
struct student s; // Structure Variable
printf("Enter information of students:nn");
printf("Enter name: "); scanf("%s",s.name);
printf("Enter roll number: "); scanf("%d",&s.roll);
printf("Enter marks: "); scanf("%f",&s.marks);
printf("nDisplaying Informationn");
printf("Name: %sn",s.name);
printf("Roll: %dn",s.roll);
printf("Marks: %.2fn",s.marks);
return 0;
}
typedef
• It is used to give a new symbolic name (alias)
to the existing entity of program.
• typedef existing name alias_name;
• typedef int unit;
• unit a,b;
typedef with structure
• alias_name variable list;
• typedef struct tag_name
{
data-type Field1;
data-type Field2;
………
} alias_name;
typedef with structure
• typedef struct book
{
char name[20];
char author[10];
int pages;
float price;
} book_bank;
• book_bank b1,b2;
Accessing Structure Member
• Member Access Operator
– Dot (.) operator
– s1.name
• Structure Pointer Operator
– Arrow (->) Operator
– s2->name
Nested Structure
• struct date
{
int day, mon, year;
};
• Struct emp
{
char name[20];
struct date birthday;
float salary;
};
Nested Structure
Struct emp
{
char name[20];
struct date
{
int day, mon, year;
} birthday;
float salary;
};
Nested Structure
• struct emp e1 = {“Ratan”,{28,12,1937},68.4};
• printf(“name =%s”,e1.name);
– Output : Ratan
• Printf(“Month of Birth=%d”,e1.birthday.mon);
– Output ??
Nested Structure
• struct emp e1 = {“Ratan”,{28,12,1937},68.4};
• printf(“name =%s”,e1.name);
– Output : Ratan
• Printf(“Month of Birth=%d”,e1.birthday.mon);
– Output : 12
Array of Structure
• struct student
{
int roll_no;
char name[20];
float marks;
} s[100];
#include <stdio.h>
struct employee
{
int emp_id;
char name[20];
float salary;
int dept_no;
int age;
};
Int main ( )
{
struct employee e[50];
int I,n;
printf(Enter No of Employee );
Scanf(“%d”,&n);
for (i=0; i<n; i++)
{
printf (“Enter employee id, name salary,
departement id and age of employee”);
scanf (“%d”,&e[i].emp_id);
scanf (“%s”,e[i].name);
scanf (“%f”,&e[i].salary);
scanf (“%d”,&e[i].dept_no);
scanf (“%d”,&e[i].age);
}
for (i=0; i<n; i++)
{
printf (“Employee id : %d”, e[i].emp_id);
printf (“Name : %s”,e[i].name);
printf (“Salary : %f”, e[i].salary);
printf (“Department ID: %d”, e[i].dept_no);
printf (“Age : %d”, e[i].age);
}
return 0;
}
Structure in Function
• Parameter Passing
• Return Value
Passing Parameter
#include <stdio.h>
struct employee
{
int emp_id;
char name[20];
float salary;
};
Int main ( )
{
struct employee e;
printf (“Enter the employee id of employee”);
scanf(“%d”,&e.emp_id);
printf (“Enter the name of employee”);
scanf(“%s”,e.name);
printf (“Enter the salary of employee”);
scanf(“%f”,&e.salary);
printdata (struct employee e); // fn Call
return 0;
}
void printdata( struct employee emp)
{
printf (“nThe employee id of employee is : %d”,emp.emp_id);
printf (“nThe name of employee is : %s”, emp.name);
printf (“nThe salary of employee is : %f”, emp.salary);
}
Return Value
#include <stdio.h>
struct employee
{
int emp_id;
char name[20];
float salary;
};
void main ( )
{
struct employee emp;
emp=getdata(); // fn Call
printf (“nThe employee id is:%d”,emp.emp_id);
printf (“nThe name is : %s”, emp.name);
printf (“nThe salary is : %f”, emp.salary);
return 0;
}
struct employee getdata( )
{
struct employee e;
printf (“Enter the employee id of employee”);
scanf(“%d”,&e.emp_id);
printf (“Enter the name of employee”);
scanf(“%s”,e.name);
printf (“Enter the salary of employee”);
scanf(“%f”,&e.salary);
return(e);
}
Union
• Definition – Same as structure
• Syntax – Same as structure
• Difference in structure and union
– Keyword – union
– Memory allocation
– Variable Storage
Syntax
• union tag_name
{
data-type Field1;
data-type Field2;
………
};
Memory Allocation
• union student
{
int roll_no;
char name[20];
float marks;
} s1,*s2;
sizeof(s1)= ????
Memory Allocation
• union student
{
int roll_no;
char name[20];
float marks;
} s1,*s2;
sizeof(s1)= 20 byte (Field with Max sixe: Name)
Structure & union

More Related Content

What's hot

Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 

What's hot (20)

C Pointers
C PointersC Pointers
C Pointers
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
This pointer
This pointerThis pointer
This pointer
 
Strings in C
Strings in CStrings in C
Strings in C
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure c
Structure cStructure c
Structure c
 

Similar to Structure & union

Presentation on structure,functions and classes
Presentation on structure,functions and classesPresentation on structure,functions and classes
Presentation on structure,functions and classes
Alisha Korpal
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
kavitham66441
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
babuk110
 

Similar to Structure & union (20)

358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Unit4
Unit4Unit4
Unit4
 
C Language Unit-4
C Language Unit-4C Language Unit-4
C Language Unit-4
 
structure
structurestructure
structure
 
Structures in C.pptx
Structures in C.pptxStructures in C.pptx
Structures in C.pptx
 
CA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxCA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptx
 
COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation
 
1. structure
1. structure1. structure
1. structure
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
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
 
Presentation on structure,functions and classes
Presentation on structure,functions and classesPresentation on structure,functions and classes
Presentation on structure,functions and classes
 
Structures
StructuresStructures
Structures
 
STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
slideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdfslideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdf
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Structures and Unions
Structures and UnionsStructures and Unions
Structures and Unions
 

More from Rupesh Mishra (6)

Cloud Computing - Introduction
Cloud Computing - IntroductionCloud Computing - Introduction
Cloud Computing - Introduction
 
Computer Graphics - Output Primitive
Computer Graphics - Output PrimitiveComputer Graphics - Output Primitive
Computer Graphics - Output Primitive
 
Ipsec
IpsecIpsec
Ipsec
 
Modern symmetric cipher
Modern symmetric cipherModern symmetric cipher
Modern symmetric cipher
 
Security
SecuritySecurity
Security
 
Cryptology
CryptologyCryptology
Cryptology
 

Recently uploaded

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 

Recently uploaded (20)

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 

Structure & union

  • 2. Content • Introduction • Structure Definition • Accessing Structure Member • Array of Structure • Pointer to Structure • Function and Structure • Union
  • 3. Introduction • User defined data type • Collection of heterogeneous data • Referred by a common name • A function can return a structure
  • 4. Definition • Collection of logically related data with same or different data-type, the logically related data are grouped together in a common name. • Structure Tag • Data Member or Fields
  • 5. Syntax • struct tag_name { data-type Field1; data-type Field2; ……… };
  • 6. Example • struct book { char name[20]; char author[10]; int pages; float price; } ;
  • 7. Declaration of Variable • struct student { int roll_no; char name[20]; float marks; } s1,*s2;
  • 8. Using Structure Tag • struct struct_tag variable-list; • struct student s1,*s2; • Variable can be declared inside(local) or outside(global) of main function
  • 9. Memory Allocation • struct student s1 = {1,”Rupesh”,67.67}; • N=sizeof(s1); • N ???? s1.roll_no s1.name s1.marks 1 R u p e s h 0 G V 67.67 6502 6504 6024 6025
  • 10.
  • 11. #include <stdio.h> struct student { char name[50]; int roll; float marks; };
  • 12. int main() { struct student s; // Structure Variable printf("Enter information of students:nn"); printf("Enter name: "); scanf("%s",s.name); printf("Enter roll number: "); scanf("%d",&s.roll); printf("Enter marks: "); scanf("%f",&s.marks);
  • 13. printf("nDisplaying Informationn"); printf("Name: %sn",s.name); printf("Roll: %dn",s.roll); printf("Marks: %.2fn",s.marks); return 0; }
  • 14. typedef • It is used to give a new symbolic name (alias) to the existing entity of program. • typedef existing name alias_name; • typedef int unit; • unit a,b;
  • 15. typedef with structure • alias_name variable list; • typedef struct tag_name { data-type Field1; data-type Field2; ……… } alias_name;
  • 16. typedef with structure • typedef struct book { char name[20]; char author[10]; int pages; float price; } book_bank; • book_bank b1,b2;
  • 17. Accessing Structure Member • Member Access Operator – Dot (.) operator – s1.name • Structure Pointer Operator – Arrow (->) Operator – s2->name
  • 18. Nested Structure • struct date { int day, mon, year; }; • Struct emp { char name[20]; struct date birthday; float salary; };
  • 19. Nested Structure Struct emp { char name[20]; struct date { int day, mon, year; } birthday; float salary; };
  • 20. Nested Structure • struct emp e1 = {“Ratan”,{28,12,1937},68.4}; • printf(“name =%s”,e1.name); – Output : Ratan • Printf(“Month of Birth=%d”,e1.birthday.mon); – Output ??
  • 21. Nested Structure • struct emp e1 = {“Ratan”,{28,12,1937},68.4}; • printf(“name =%s”,e1.name); – Output : Ratan • Printf(“Month of Birth=%d”,e1.birthday.mon); – Output : 12
  • 22. Array of Structure • struct student { int roll_no; char name[20]; float marks; } s[100];
  • 23.
  • 24. #include <stdio.h> struct employee { int emp_id; char name[20]; float salary; int dept_no; int age; };
  • 25. Int main ( ) { struct employee e[50]; int I,n; printf(Enter No of Employee ); Scanf(“%d”,&n);
  • 26. for (i=0; i<n; i++) { printf (“Enter employee id, name salary, departement id and age of employee”); scanf (“%d”,&e[i].emp_id); scanf (“%s”,e[i].name); scanf (“%f”,&e[i].salary); scanf (“%d”,&e[i].dept_no); scanf (“%d”,&e[i].age); }
  • 27. for (i=0; i<n; i++) { printf (“Employee id : %d”, e[i].emp_id); printf (“Name : %s”,e[i].name); printf (“Salary : %f”, e[i].salary); printf (“Department ID: %d”, e[i].dept_no); printf (“Age : %d”, e[i].age); } return 0; }
  • 28. Structure in Function • Parameter Passing • Return Value
  • 29. Passing Parameter #include <stdio.h> struct employee { int emp_id; char name[20]; float salary; };
  • 30. Int main ( ) { struct employee e; printf (“Enter the employee id of employee”); scanf(“%d”,&e.emp_id); printf (“Enter the name of employee”); scanf(“%s”,e.name); printf (“Enter the salary of employee”); scanf(“%f”,&e.salary); printdata (struct employee e); // fn Call return 0; }
  • 31. void printdata( struct employee emp) { printf (“nThe employee id of employee is : %d”,emp.emp_id); printf (“nThe name of employee is : %s”, emp.name); printf (“nThe salary of employee is : %f”, emp.salary); }
  • 32. Return Value #include <stdio.h> struct employee { int emp_id; char name[20]; float salary; };
  • 33. void main ( ) { struct employee emp; emp=getdata(); // fn Call printf (“nThe employee id is:%d”,emp.emp_id); printf (“nThe name is : %s”, emp.name); printf (“nThe salary is : %f”, emp.salary); return 0; }
  • 34. struct employee getdata( ) { struct employee e; printf (“Enter the employee id of employee”); scanf(“%d”,&e.emp_id); printf (“Enter the name of employee”); scanf(“%s”,e.name); printf (“Enter the salary of employee”); scanf(“%f”,&e.salary); return(e); }
  • 35. Union • Definition – Same as structure • Syntax – Same as structure • Difference in structure and union – Keyword – union – Memory allocation – Variable Storage
  • 36. Syntax • union tag_name { data-type Field1; data-type Field2; ……… };
  • 37. Memory Allocation • union student { int roll_no; char name[20]; float marks; } s1,*s2; sizeof(s1)= ????
  • 38. Memory Allocation • union student { int roll_no; char name[20]; float marks; } s1,*s2; sizeof(s1)= 20 byte (Field with Max sixe: Name)