|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小甲鱼视频的042讲中 讲了一个函数将两个数调换用了指针 但是最终还是靠取值赋值来实现的 我想能不能直接设一个*temp 然后交换指针呢,经试验是失败的 但是为什么呢?code:
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void swap ( int *q1,int *q2 );
int main()
{
int a,b;
int *ap,*bp;
ap = &a;
bp = &b;
scanf("%d %d",ap,bp);
swap(ap,bp);
printf("%d >%d\n",*ap,*bp);
return 0;
} /* ----- end of function main ----- */
void swap ( int *q1,int *q2 )
{
int *temp;
printf("check\n");
if(*q1<*q2)
{
printf("swap\n");
temp = q2;
q2 = q1;
q1 = temp;
}
} /* ----- end of function swap ----- */
|
|