第2周项目1函数参数传递

/*
 *Copyright(c++)2014,烟台大学计算机学院
 *All rights reserved.
 *文件名称:text.cpp
 *作者:李宁
 *完成日期:2015.9.11
 *版本号:vc++6.0
 *
 *问题描述:交换两个整形变量
 *输入描述:两个整数
 *程序输出:两个交换后的整数值
 */
#include<iostream>
using namespace std;
void myswap1(int *,int *);
void myswap2(int &a,int &b);
int main()
{
	int a,b;
	cin>>a>>b;
	int t;
	t=a;
	a=b;
	b=t;
	cout<<a<<" "<<b<<endl;
    void myswap1(int *a,int *b);
    cout<<a<<" "<<b<<endl;
    void myswap2(int &a,int &b);
    cout<<a<<" "<<b<<endl;
	return 0;
}

void myswap1(int *a,int *b)
{
	int t;
	t=*a;
	*a=*b;
	*b=t;
}
void myswap2(int &a,int &b)
{

	int t;
	t=a;
	a=b;
	b=t;
}


运行结果:第2周项目1函数参数传递_第1张图片

知识点总结:熟悉了指针和地址的定义和用法

学习心得:

指针和地址适合函数的调用,整数的直接传递不适合

你可能感兴趣的:(第2周项目1函数参数传递)