Access the Same Data in Different Ways Using a Union

Learn how to access the same data in several different ways using a union.

A union is required when we have to interact with hardware. For example, when interacting with the hardware, sometimes we have to access 4 bytes in one go and sometimes each byte individually. A union allows us to access the same data in several different ways.

Example program 1: Accessing 8, 4, and 1 byte

RUN the code given below and see its output!

Get hands-on with 1400+ tech skills courses.