练习题:将两个int类型数值交换
#include <stdio.h> void swap(int*,int*); int main(void){ int bin = 107, hex = 0x5f1043; swap(&bin,&hex); printf("%d %d ",bin,hex); return 0; } void swap(int *p1, int *p2) { int tmp = *p1; *p1 = *p2; *p2 =tmp; }
练习题:将两个字符串交换
#include <stdio.h> void swap(char**,char**); int main(void){ char *sz1 ="World "; char *sz2 = "Hello "; swap(&sz1,&sz2); printf("%s %s ",sz1,sz2); return 0; } void swap(char **sz1, char **sz2) { char *tmp = *sz1; *sz1 = *sz2; *sz2 = tmp; }