Files
LanguageBasics/Endian/C/endian.c
2025-06-07 11:38:03 -04:00

25 lines
571 B
C

#include <stdio.h>
void show_memory(const char* begin, size_t length)
{
size_t i = 0;
for (; i < length; i++)
{
printf(" %.2x", 0xff & begin[i]); // 0xff is necessary due to type promotion
}
printf("\n");
}
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
float f = 42654.2312f;
int i = 7753238;
printf("Printing float %f with size %ld\n", f, sizeof(f));
show_memory((char*)&f, sizeof(f));
printf("Printing int %d with size %ld\n", i, sizeof(f));
show_memory((char*)&i, sizeof(i));
return 0;
}