
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Explain the concept of union of structures in C language
If the structure is nested inside a union, it is called as a union of structures. There is a possibility to create a union inside a structure in C programming language.
Example
Following is the C program for union of structures −
#include<stdio.h> struct x { int a; float b; }; union z{ struct x s; }; main ( ){ union z u; u.s.a = 10; u.s.b = 30.5; printf("a=%d", u.s.a); printf("b=%f", u.s.b); getch ( ); }
Output
When the above program is executed, it produces the following result −
a= 10 b = 30.5
Example
Given below is another C program for union of structures −
#include<stdio.h> union abc{ int a; char b; }v; int main(){ v.a=90; union abc *p=&v; printf("a=%d
",v.a);//90 printf("b=%c
",v.b);//Z printf("a=%d b=%c
",p->a,p->b);//90 Z printf("%d",sizeof(union abc));//4 return 0; }
Output
When the above program is executed, it produces the following result −
a=90 b=Z a=90 b=Z 4
- Related Articles
- Explain the array of structures in C language
- Explain the concept of Sorting in C language
- Explain the concept of stack in C language
- Explain the concept of pointers in C language
- Explain the concept of Arithmetic operators in C language
- Explain the concept of pointer accessing in C language
- Explain the concept of Linked list in C language
- Explain the Union to pointer in C language
- Explain the concept of Uninitialized array accessing in C language
- Explain the concept of logical and assignment operator in C language
- Explain structures using typedef keyword in C language
- Explain the concept of pointer to pointer and void pointer in C language?
- Explain the concept of one and two dimensional array processing using C language
- What is union of structure in C language?
- Explain bit field in C language by using structure concept

Advertisements