指针2

作者: 时间:2020-07-09 点击数:

问题:输入任意两个整数,从大到小输出
分析:
      输入任意两个整数--》a,b
   if (a<b)
      {a和b内容交换}
   输出a,b的值
设计一个函数,实现两个数据的交换
void swap2(int *p,int *q)
结论:
    通过形参能够改变实参值的方法(函数返回一个以上的值)

void swap(int p,int q){
int t;
t=p; p=q; q=t;}
void swap1(int *p,int *q){
//交换p和q值
int * t;
t=p; p=q; q=t;}
void swap2(int *p,int *q){
//*p等价于a,*q等价于b;在函数中交换*p与*q,*p和*q都属于int类型
int t;
t=*p; *p=*q; *q=t;}

上一页 [1] [2]

Copyright© 2020 Anyang Institute of Technology.All rights reserved.

学院地址:河南省安阳市黄河大道西段