练习题:将两个int类型数值交换

#include <stdio.h>

void swap(int*,int*);

int main(void){

    int bin = 107, hex = 0x5f1043;
    
    swap(&bin,&hex);
    
    printf("%d %d\n",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\0";
    char *sz2 = "Hello\0";

    swap(&sz1,&sz2);

    printf("%s %s\n",sz1,sz2);

    return 0;
}

void swap(char **sz1, char **sz2)
{
    char *tmp = *sz1;
    *sz1 = *sz2;
    *sz2 = tmp;
}

 

posted on 2018-05-23 17:03  你不知道的浪漫  阅读(4054)  评论(0编辑  收藏  举报