下面的函數將輸出什麼結果?
1 const char *s = "abcdef"; 2 show_bytes((byte_pointer) s, strlen(s));
其中字母'a'~'z'的ASCII碼為0x61~0x7A。
show_bytes()函數定義如下:
1 #include <stdio.h>
2
3 typedef unsigned char *byte_pointer;
4
5 void show_bytes(byte_pointer p, int n)
6 {
7 int i;
8 for(i = 0; i < n; ++i)
9 {
10 printf(" %.2x", p[i]);
11 }
12 printf("\n");
13 }
將輸出:61 62 63 64 65 66
在使用ASCII碼作為字符碼的任何系統上都將得到相同的結果,與字節順序和字大小規則無關。因而,文本數據比二進制數據具有更強的平台獨立性。