#include <stdio.h> void swap(int *p,int *q) { int i; i=*p,*p=*q,*q=i; } main() { int a=5,b=4,*p,*q; p=&a;q=&b; swap(p,q); printf("%d\n%d\n",a,b); return 0; }
4
5
--------------------------------
Process exited after 0.8483 seconds with return value 0
请按任意键继续. . .
总结:中间做错两次(其中包括“,”的中文输入)总结原因是因为一开始对于void和swap函数真正含义的模糊 所以在主函数之前的声明出现了无法输出值的错误 经改正和掌握现在已经可以很好地运用
#include<stdio.h> void swap(int *p,int *q) { int *m; *m=*p; *p=*q; *q=*m; } main() { int a,b; swap(&a,&b); printf("%d\n,%d\n",a,b); }
--------------------------------
Process exited after 15.81 seconds with return value 255
请按任意键继续. . .
总结:出现了程序错误 不知道如何修改.....
#include<stdio.h> void swap(int *p,int *q) { int *m; m=p; p=q; q=m; } main() { int a,b; swap(&a,&b); printf("%d\n%d\n",a,b); }
0
1
--------------------------------
Process exited after 0.6496 seconds with return value 4
请按任意键继续.
总结:在此子函数中 进行更换的是swap中的p和q 而主函数中的ab并没有交换
#include<stdio.h> int *comp(int *m,int *n) { return *m>*n? m:n; } int main() { int a,b,*p; scanf("%d\n%d\n",&a,&b); p=comp(&a,&b); printf("max=%d\n",*p); }
89
max=9
--------------------------------
Process exited after 8.873 seconds with return value 6
请按任意键继续. . .
总结:第一次写完结果
8 9
max=56
--------------------------------
Process exited after 27 seconds with return value 7
请按任意键继续. . .
不知道为什么会出现这样的错误 然后百度后在comp函数前添加*之后能得出最大值的结果
我理解的:应该是在子函数中定义了comp的这个函数的指针 然后把m n函数定义进去 再定义p=comp的地址 然后由p输出比较之后的值