fork download
  1. #include <stdio.h>
  2.  
  3. union{
  4. char arr[4];
  5. long data;
  6. } test;
  7.  
  8. int main() {
  9. char c = 'a';
  10.  
  11. /* Test platform Endianness */
  12. for(int x = 0; x < 4; x++)
  13. test.arr[x] = c++;
  14. if ( test.data == 0x61626364 )
  15. /* It’s big endian and you do your stuff */
  16. {
  17. printf("Big endian");
  18. } else {
  19. printf("Little endian");
  20. }
  21. }
Success #stdin #stdout 0s 5284KB
stdin
123
stdout
Little endian