fork download
  1. #include <stdio.h>
  2.  
  3. union{
  4. char arr[4];
  5. long data;
  6. } test;
  7.  
  8. int main() {
  9. printf("endian.c\n\n");
  10.  
  11. printf("sizeof(char) = %lu\n", sizeof(char));
  12. printf("sizeof(short) = %lu\n\n", sizeof(short));
  13.  
  14. short x = 1;
  15.  
  16. short *w = &x; /* w to wskaznik na zmienna typu short */
  17.  
  18. printf("*w = %d\n\n", *w);
  19.  
  20. char *b = (char*)w; /* b to wskaznik na zmienna typu char */
  21.  
  22. /* wskazniki w i b przechowuja ten sam adres */
  23.  
  24. printf("w = %p\n", w);
  25. printf("b = %p\n\n", b);
  26.  
  27. /* test architektury */
  28.  
  29. printf("*b = %d\n", *b);
  30. printf("*(b+1) = %d\n", *(b+1));
  31. }
  32.  
Success #stdin #stdout 0.01s 5528KB
stdin
123
stdout
endian.c

sizeof(char) = 1
sizeof(short) = 2

*w = 1

w = 0x7ffc9362f9d6
b = 0x7ffc9362f9d6

*b = 1
*(b+1) = 0