回 帖 发 新 帖 刷新版面

主题:[讨论]帮忙改错啊

#include<stdio.h>
void main()
{
int a,b;
a=3;
b=4;
swap(a,b);
printf("%d,%d\n",a,b);
}
void swap(int x,int y)
{
int t;
t=x;x=y;y=t;
}

int类型做形式参数,无法蒋实际参数的变化信息返回,应该怎么改呢...新手上路,请大家多多帮忙,感激不尽...

回复列表 (共1个回复)

沙发

#include <stdio.h>

void swap( int* px, int* py );

int main()
{
    int a=3, b=4;
    swap( &a, &b );
    printf( "%d,%d\n", a, b );

    return 0;
}

void swap( int* px, int* py )
{
    int t = *px;
    *px = *py;
    *py = t;
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册