C++Primer Plus第七章函数---C++编程 7.3编程练习3 函数传值的两个问题

这里涉及到两个问题
1,结构体传值。
2,结构体指针传值的问题。

#pragma region 3.cpp 7.3
/*
3.下面是一个结构声明:
struct box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
		};
a.编写一个函数,按值传递box结构,并显示每个成员的值。
b.编写一个函数,传递box 结构的地址,并将volume成员设置为其他三维长度的乘积。
c.编写一个使用这两个函数的简单程序。
*/
#if 1
#include<iostream>
struct Box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};
void box_1(Box);
void box_2(Box*);
int main()
{
	using namespace std;
	Box box = {"zhang yong jiang",90,40,160,0};
	box_1(box);
	box_2(&box);
	box_1(box);
	return 0;
}

//函数的实现
void box_1(Box box)
{
	std::cout << box.maker << "\t" << box.height << "\t" << box.width
				<< "\t" << box.length << "\t" << box.volume << "\t";
	std::cout << std::endl;
}
void box_2(Box* pbox)
{
	pbox->volume = pbox->height * pbox->width * pbox->length;
}
#endif 
#pragma endregion
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值