标题:如何通过另一个函数使两个指针指向交换?
只看楼主
city忆
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-12-10
 问题点数:0 回复次数:0 
如何通过另一个函数使两个指针指向交换?
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    void swap(int **p1,int **p2);
    int a,b,*s1,*s2;
    printf("enter the numbers:");
    scanf("%d%d",&a,&b);
    s1=&a;
    s2=&b;
    if(a<b) swap(s1,s2);
    printf("the order is %d%d\n",*s1,*s2);
    printf("%d%d",a,b);

    return 0;
}

void swap(int **p1,int **p2)
{
int term;
term=**p1;**p1=**p2;**p2=term;
}
这个是错的,我的目的是通过交换指针s1s2的指向,使s1指向最大值,然后输出。同时保持ab的值不发生改变。
搜索更多相关主题的帖子: include numbers 如何 
2011-12-10 19:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-357464-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.236667 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved