English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How to write a C program that will print 1 when compiled and run on a little-endian machine and will print 0 when complied and run on a big-endian machine. The program should run on any machine regardless of its word size. (You can assume that a variable declared as unsigned char occupies one byte.)

2007-02-01 10:36:51 · 2 answers · asked by highsharp06 1 in Science & Mathematics Other - Science

2 answers

Well, that is the absolute beauty of C, isn't it. You can write a program that will give different results on different machines. Very useful for banking and space shots.

2007-02-02 21:20:45 · answer #1 · answered by ZORCH 6 · 0 0

If an unsigned char is only one byte long, the endianness should not be a factor. This assumes UTF-8 character sets as well...

2007-02-01 18:44:04 · answer #2 · answered by cfpops 5 · 0 0

fedest.com, questions and answers