I had for class to do a code which shows if machine is big or little endian. I made this:
#include <stdio.h>
typedef unsigned char *byte_pointer;
int show_bytes(int x) {
byte_pointer a = (byte_pointer)&x;
int i;
printf("%c", a[0]); // why here when printing a[0] does not give the ascii representation?
if (a[0] == 0x01)
return 1;
return 0;
}
int isEndian() {
int i = 1;
return show_bytes(i);
}
int main(int argc, char **argv){
int a = isEndian();
printf("%d", a);
}
And I do not understand why when printing back the char[0]
on a little endian machine, does not print the unicode representation of 1
?