#include<stdio.h>

int main(){ 

union{
  int i;
  //sizeof operator yields number of bytes required to store a type
  char c[sizeof(int)];
} u;

//%1d is long unsigned int conversion p 154, Kernighan and Ritchie 
printf("sizeof(int) = %ld bytes\n",sizeof(int));

printf("each char is one byte so second part in the union is a four-byte array\n");

printf("short int is often 16 bits and long int is 32 and int is either 16 or 32\n");

u.i = 1;

for (int k = 0; k < 4; k++)
  printf("k = %d, u.c[k] = %d\n",k, u.c[k]);  

printf("so first 4 bytes, u.i = %d\n",u.i);

if (u.c[0] == 1)
   printf("little endian\n");
else
   printf("big endian\n");

}
