深入理解计算机系统第二版习题解答CSAPP 2.7

下面的函数将输出什么结果?

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码作为字符码的任何系统上都将得到相同的结果,与字节顺序和字大小规则无关。因而,文本数据比二进制数据具有更强的平台独立性。

posted @ 2014-11-16 14:14  枫竹梦  阅读(503)  评论(0编辑  收藏  举报