第15周项目3-玩玩指针
2014-12-03 15:01
204 查看
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:刘畅 * 完成日期:2014 年 12 月 3 日 * 版 本 号:v1.0 * * 问题描述:试试使用了指针的程序; * 输入描述:啥也不用输; * 程序输出:输出该输出的。 。
(1)
#include <iostream> using namespace std; int main( ) { int *p1,*p2,a,b,t; cin>>a>>b; p1=&a; p2=&b; if (*p1<*p2) { t=*p1; *p1=*p2; *p2=t; } cout<<"Max="<<a<<" Min="<<b<<endl; return 0; }运行结果:
(2)
#include <iostream> using namespace std; int main( ) { int *p1,*p2,t; p1=new int (100); p2=new int (100); cin>>*p1>>*p2; if (*p1<*p2) { t=*p1; *p1=*p2; *p2=t; } cout<<"Max="<<*p1<<" Min="<<*p2<<endl; delete p1; delete p2; return 0; }运行结果:
(3)
#include <iostream> using namespace std; void jiaohuan(int *p1,int *p2); int main( ) { int a,b; cin>>a>>b; jiaohuan(&a,&b); cout<<a<<" "<<b<<endl; return 0; } void jiaohuan(int *p1,int *p2) { int t; t=*p1; *p1=*p2; *p2=t; }运行结果:
(4)
#include <iostream> using namespace std; void ast(int x,int y,int *cp,int *dp) { *cp=x+y; *dp=x-y; } int main( ) { int a,b,c,d; cin>>a>>b; ast(a,b,&c,&d); cout<<c<<" "<<d<<endl; return 0; }运行结果:
学习心得:
做完这几个题,基本上是理解指针的运用和作用了。
相关文章推荐
- 第15周项目3-指针当形参-变量交换
- 第15周项目3-在OJ上玩指针(1)
- 第15周上机实践项目3——在OJ上玩指针(1)
- 第15周项目2阅读程序(指针+条用函数)
- 2014秋C++ 第15周项目3参考解答 在OJ上玩指针
- 2014秋C++ 第15周项目 指针基础
- 第15周 项目3-玩指针(1)
- 第15周项目3-在OJ上玩指针之两数和与差(用参数带回结果)
- 第15周项目-在OJ上玩指针(指针做形参)
- 第15周项目3指针的基本操作(2)分配和删除空间
- 第15周项目3-在OJ上玩指针(2)
- 第15周项目1-指针单步调试
- 第15周项目3-在OJ上玩指针之指针的基本操作(2)
- 第15周项目3(4)-在OJ上玩指针
- 第15周项目3(1)-在OJ上玩指针
- 第15周项目3-指针的基本操作(new-delete)-输出最值
- 第15周项目3-在OJ上玩指针(3)
- 第15周项目-在OJ上玩指针(指针的基本操作)
- 第15周上机实践项目3——在OJ上玩指针(3)
- 第15周项目3指针当形参