第二次作业

#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输出比较之后的值

转载于:https://www.cnblogs.com/ljxwtw/p/6601181.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值