| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
#include <stdio.h> 
int a=1,b=2,c=3,*p1,*p2,*p3,*t; 
void swap(int *q1,int *q2); 
void main() 
{ 
        p1 = &a; 
        p2 = &b; 
        p3 = &c; 
        swap(*p1,*p2); 
        swap(*p1,*p3); 
        swap(*p2,*p3); 
        printf("%d %d %d",a,b,c); 
} 
 
void swap(int *q1,int *q2) 
{ 
        if(*q1<*q2) 
        { 
                int temp; 
                temp = *q1; 
                *q1 = *q2; 
                *q2 = temp; 
        } 
}
swap函数两个参数都是int *类型,*p1 *p2 *p3这些是int类型,把int变量传给int *参数当然会出错 
把调用函数里p1 p2 p3前面的*去掉就可以了 
#include <stdio.h> 
int a=1,b=2,c=3,*p1,*p2,*p3,*t; 
void swap(int *q1,int *q2); 
void main() 
{ 
        p1 = &a; 
        p2 = &b; 
        p3 = &c; 
        swap(p1,p2); 
        swap(p1,p3); 
        swap(p2,p3); 
        printf("%d %d %d",a,b,c); 
} 
 
void swap(int *q1,int *q2) 
{ 
        if(*q1<*q2) 
        { 
                int temp; 
                temp = *q1; 
                *q1 = *q2; 
                *q2 = temp; 
        } 
} 
 
 
 |   
 
 
 
 |