Endianness and the Union
Get introduced to the endianness, i.e., little-endian and big-endian storage.
We'll cover the following...
Endianness
Let’s understand the union in more detail with the help of endianness. Have a look at the output of the code given below!
Press + to interact
#include <stdio.h>int main( ){// union declarationunion a{int i ;char ch[ 4 ] ;} ;// Declares union variableunion a z ;// Assign value to union memberz.i = 512 ;// Print values of union membersprintf ( "%d %d %d %d %d\n", z.i, z.ch[ 0 ], z.ch[ 1 ] , z.ch[ 2 ], z.ch[ 3 ] ) ;}
The binary of 512 is 00000000 00000000
...