《深入理解计算机系统》(第二版)第二章中的一题目

#include <stdio.h>                                      
#include
<stdlib.h>
#include
<malloc.h>
#include
<math.h>
#include
<string.h>
typedef unsigned
char *byte_pointer;
void show_bytes(byte_pointer s){
printf(
"%c ",s);
printf(
"\n");
}
void inplace_swap(int *x,int *y){
*y=*x ^ *y;
show_bytes((byte_pointer)
*x);
show_bytes((byte_pointer)
*y);
printf(
"\n");
*x=*x ^ *y;
show_bytes((byte_pointer)
*x);
show_bytes((byte_pointer)
*y);
printf(
"\n");
*y=*x ^ *y;
show_bytes((byte_pointer)
*x);
show_bytes((byte_pointer)
*y);
printf(
"\n");
}
void main()
{
int m=0x61,n=0x62;
printf(
"原来x为%c ",(byte_pointer)m);
printf(
"原来y为%c ",(byte_pointer)n);
printf(
"\n");
inplace_swap(
&m,&n);
show_bytes((byte_pointer)m);
show_bytes((byte_pointer)n);
}
posted @ 2011-07-18 18:21  在云中漫步  阅读(236)  评论(0编辑  收藏  举报