当前位置:网站首页>结构体传参-C语言
结构体传参-C语言
2022-08-04 05:31:00 【crazy__xieyi】
struct S
{
int data[1000];
int num;
};
struct S s = { {1,2,3,4}, 1000};//结构体传参
void print1(struct S s)
{
printf("%d\n", s.num);
}
//结构体地址传参
void print2(struct S* ps)
{
printf("%d\n", ps->num);
}
int main()
{
print1(s); //传结构体 传值
print2(&s); //传地址 传址
return 0;
}
上面的print1 和print2 函数哪个好些?
函数传参的时候,参数是需要压栈,会有时间和空间上的系统开销。
如果传递一个结构体对象的时候,结构体过大,参数压栈的的系统开销比较大,所以会导致性能的下降。
所以,结构体传参的时候,要传结构体的地址。
边栏推荐
- LeetCode_Dec_2nd_Week
- Fabric v1.1 环境搭建
- file permission management ugo
- Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
- Chapter One Introduction
- 第三章 标准单元库(上)
- MNIST手写数字识别 —— Lenet-5首个商用级别卷积神经网络
- Question 1000: Input two integers a and b, calculate the sum of a+b, this question is multiple sets of test data
- MySQL批量修改时间字段
- 深度学习理论——过拟合、欠拟合、正则化、优化器
猜你喜欢
随机推荐
Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
The second official example analysis of the MOOSE platform - about creating a Kernel and solving the convection-diffusion equation
[Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
[开发杂项][调试]debug into kernel
深度学习,“粮草”先行--浅谈数据集获取之道
tmux概念和使用
(Navigation page) OpenStack-M version - manual construction of two nodes - with video from station B
Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
Deep Learning Theory - Initialization, Parameter Adjustment
arm-2-基础阶段
Amazon Cloud Technology Build On-Amazon Neptune's Knowledge Graph-Based Recommendation Model Building Experience
Pytest common plug-in
亚马逊云科技Build On-Amazon Neptune基于知识图谱的推荐模型构建心得
集合--LinkedList
target has libraries with conflicting names: libcrypto.a and libssl.a.
arm learning-1-development board
Thunderbolt turns off automatic updates
[日常办公][杂项][vscode]tab space
arm-3-中断体系结构
SQL注入详解









