Problem Solving Through C (BCA) 1st Sem Previous Year Solved Question Paper 2022

Practice Mode:
20.

What is a Union ? Give example.

Explanation

A union in C is a data structure that allows you to store different data types in the same memory location. It saves memory by sharing the same memory space for its members. Only one member can hold a value at a time. For example:

union MyUnion {

int x;

float y;

char z;

};

In this union, MyUnion, you can store either an integer, a float, or a character, but only one at a time.