c++ - 为什么我无法在这个问题中打印长度值?
问题描述
#include<stdio.h>
#include<stdlib.h>
struct rect
{
int length;
int breadth;
};
void initialize(struct rect *r,int l , int b)
{
r->length=l;
r->breadth=b;
}
void changelength(struct rect *r,int l)
{
r->length=l;
}
int area(struct rect r)
{
return(r.length*r.breadth);
}
int main()
{
struct rect r;
initialize(&r,10,5);
changelength(&r,3);
area(r);
printf("The rectangle is %d and %d\n",initialize);
printf("The length is %d\n",changelength);
printf("The area is %d",area(r));
return 0;
}
解决方案
你似乎想要的是这样的:
struct rect r;
initialize(&r, 10, 5);
printf("The rectangle is %d and %d\n", r.length, r.breadth);
changelength(&r, 3);
printf("The length is %d\n", r.length);
printf("The area is %d\n", area(r));
推荐阅读
- wordpress - 如何正确测试 wordpress Cron 作业?
- python - /pytorch/aten/src/TH/generic/THTensorRandom.cpp:325 处的无效多项分布(遇到概率条目 < 0)
- c# - 使用单个 XML 节点中包含的对象数组将 Json 反序列化为 XML
- react-native - 如何从 json react-native-material-dropdown 获取 id
- javascript - 如何从使用 ngFor 指令动态添加的 HTML 表中恢复标题单元格数据
- json - 在 API 发布请求中将纪元时间作为日期传递
- c# - 在我的 A.CallTo FakeItEasy 方法中无法获得正确的参数
- telegram-bot - 如何避免 Bot 分组重复命令?
- python-3.x - 如何使用 pyside2 插槽函数共享数据?
- excel - 在选项卡中以 mm/dd/yy 格式显示日期