一个C语言指针问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:14:46
swap(int *pt1,int *pt2)
{int temp;
temp=*pt1;
*pt1=*pt2;
*pt2=temp;
}
exchange(int *q1,int*q2,int*q3)
{if(*q1< *q2) swap(*q1,*q2);
if(*q1< *q3) swap(*q1,*q3);
if(*q2< *q3) swap(*q2,*q3);
}
#include<stdio.h>
void main()
{int a,b,c,*p1,*p2,*p3;
scanf("%d,%d,%d",&a,&b,&c);
p1=&a;p2=&b;p3=&c;
exchange(p1,p2,p3);
printf("\n%d,%d,%d",a,b,c);}
我不知道哪里错了

swap参数为指针,你给传了值。

exchange(int *q1,int*q2,int*q3)
{if(*q1< *q2) swap(q1,q2);
if(*q1< *q3) swap(q1,q3);
if(*q2< *q3) swap(q2,q3);

}

调用exchange挺明白,怎么这里糊涂了

1楼胡说八道。#include<stdio.h>放中间也无不可,只是不良习惯,

楼主的代码好恐怖...#include <stdio.h>应该放在最上面,函数也不指定返回类型,而且,main函数这样写不可以吗?
void main()
{
int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
exchange(&a,&b,&c);
printf("\n%d,%d,%d",a,b,c);
}

swap(int *pt1,int *pt2)
{int temp;
temp=*pt1;
*pt1=*pt2;
*pt2=temp;
}
exchange(int *q1,int*q2,int*q3)
{if(*q1< *q2) swap(q1,q2);//主要是这里变了
if(*q1< *q3) swap(q1,q3);
if(*q2< *q3) swap(q2,q3);
}
#include<stdio.h>
void main()
{int a,b,c,*p1,*p2,*p3;
scanf("%d%d%d",&a,&b,&c);//输入别加逗号
p1=&a;p2=&b;p3=&c;
exchange(p1,p2,p3);
printf("\n%d,%d,%d",a,b