结构体和函数
2014-02-24 17:30
155 查看
结构体和函数
结构体是一种数据类型,作为数据类型,它就可以定义变量,同时也可以作为函数的形式参数,或者让函数的返回值为一个结构体类型。下面通过一个代码来说明这一点:
#include <iostream>
using namespace std;
struct people
{
int weight;
int tall;
bool sex;
int age;
};
const int class=60;
people &sum(people1,people2);
void show(people);
int main()
{
people a=(80,190,1,19);
people b=(90,200,1,21);
people *number=&total(a,b);
cout<<"两人总计为:"<<endl;
show(*number);
delete number;
return 0;
}
people &sum(people t1,people t2)
{
people *total=new people;
total->tall=t1.tall+t2.tall;
total->weight=t1.weight+t2.weight;
return *total;
}
void show(people t3)
{
cout<<t3.tall<<endl;
}
结构体是一种数据类型,作为数据类型,它就可以定义变量,同时也可以作为函数的形式参数,或者让函数的返回值为一个结构体类型。下面通过一个代码来说明这一点:
#include <iostream>
using namespace std;
struct people
{
int weight;
int tall;
bool sex;
int age;
};
const int class=60;
people &sum(people1,people2);
void show(people);
int main()
{
people a=(80,190,1,19);
people b=(90,200,1,21);
people *number=&total(a,b);
cout<<"两人总计为:"<<endl;
show(*number);
delete number;
return 0;
}
people &sum(people t1,people t2)
{
people *total=new people;
total->tall=t1.tall+t2.tall;
total->weight=t1.weight+t2.weight;
return *total;
}
void show(people t3)
{
cout<<t3.tall<<endl;
}
相关文章推荐
- 编程之美 set 5 寻找数组中最大值和最小值
- Oracle中having1子句的用法
- iOS学习之二十:应用的归档打包以及distribution测试和上传到App Store
- JS 控制check复选框全选/反选
- Powercenter 基础知识介绍- 4
- 反转链表
- Struts2防止表单重复提交(源代码)
- Android进程与线程详解
- Ubuntu消息菜单(MessagingMenu)API
- LA4513 Stammering Aliens
- bae 收费
- 将多个js函数绑定到onload事件上
- Powercenter 基础知识介绍 - 3
- 494 - Kindergarten Counting Game
- 解析xml的问题未解决
- 关于白平衡
- Hello Kiki hdu 3579 求解一元线性同余方程组ps:中国剩余定理
- B - 产生冠军
- Spring aop 基于schema的AOP支持及JoinPoint的使用、如何使用CGLIB代理
- cocos2dx常见的46中+22中动作详解