当前位置:网站首页>结构体传参-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 函数哪个好些?
函数传参的时候,参数是需要压栈,会有时间和空间上的系统开销。
如果传递一个结构体对象的时候,结构体过大,参数压栈的的系统开销比较大,所以会导致性能的下降。
所以,结构体传参的时候,要传结构体的地址。
边栏推荐
猜你喜欢
MNIST手写数字识别 —— ResNet-经典卷积神经网络
Brief description of database and common operation guide
Cut the hit pro subtitles export of essays
How to get started with MOOSE platform - an example of how to run the official tutorial
arm学习-1-开发板
Detailed steps to install MySQL
LeetCode_Nov_5th_Week
MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification
MNIST手写数字识别 —— Lenet-5首个商用级别卷积神经网络
tmux概念和使用
随机推荐
度量学习(Metric learning)—— 基于分类损失函数(softmax、交叉熵、cosface、arcface)
[日常办公][ssh]cheatsheet
LeetCode_Nov_3rd_Week
Brief description of database and common operation guide
Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
打金?工作室?账号被封?游戏灰黑产离我们有多近
Copy Siege Lion's Annual "Battle" | Review 2020
The second official example analysis of the MOOSE platform - about creating a Kernel and solving the convection-diffusion equation
arm学习-1-开发板
典型CCN网络——efficientNet(2019-Google-已开源)
Golang environment variable settings (2)--GOMODULE & GOPROXY
Amazon Cloud Technology Build On 2022 - AIot Season 2 IoT Special Experiment Experience
集合--LinkedList
通用解决端口占用问题
Pytest常用插件
MNIST handwritten digit recognition - based on Mindspore to quickly build a perceptron to achieve ten categories
MNIST手写数字识别 —— Lenet-5首个商用级别卷积神经网络
arm-2-基础阶段
语音驱动嘴型与面部动画生成的现状和趋势
LeetCode_Nov_2nd_Week