Monday, May 24, 2010

How to I write a C program???

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.)

How to I write a C program???
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.
Reply:If an unsigned char is only one byte long, the endianness should not be a factor. This assumes UTF-8 character sets as well...

trading cards

No comments:

Post a Comment