当前位置:网站首页>结构体传参-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 函数哪个好些?
函数传参的时候,参数是需要压栈,会有时间和空间上的系统开销。
如果传递一个结构体对象的时候,结构体过大,参数压栈的的系统开销比较大,所以会导致性能的下降。
所以,结构体传参的时候,要传结构体的地址。
边栏推荐
猜你喜欢

文件编辑器
![[Deep Learning Diary] Day 1: Hello world, Hello CNN MNIST](/img/06/6f49260732e5832edae2ec80aafc99.png)
[Deep Learning Diary] Day 1: Hello world, Hello CNN MNIST

Golang environment variable settings (2)--GOMODULE & GOPROXY

多层LSTM

CSDN spree -- college round table spree

AWS uses EC2 to reduce the training cost of DeepRacer: DeepRacer-for-cloud practical operation

Shell脚本执行的三种方式

file permission management ugo

LeetCode_Dec_2nd_Week

lstm pipeline 过程理解(输入输出)
随机推荐
MNIST手写数字识别 —— 基于Mindspore快速构建感知机实现十分类
[日常办公][杂项][vscode]tab space
How to get started with MOOSE platform - an example of how to run the official tutorial
arm交叉编译
MOOSE平台使用入门攻略——如何运行官方教程的例子
[开发杂项][VS Code]remote-ssd retry failed
TensorRT 5 初步认识
集合--LinkedList
LeetCode_Nov_2nd_Week
Copy Siege Lions "sticky" to AI couplets
jdbc:mysql://localhost:3306/student?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8时报错
[Daily Office][Miscellaneous][vscode]tab space
FAREWARE ADDRESS
AWS uses EC2 to reduce the training cost of DeepRacer: DeepRacer-for-cloud practical operation
ideal life
LeetCode_22_Apr_4th_Week
Postgresql snapshot
题目1000:输入两个整数a和b,计算a+b的和,此题是多组测试数据
LeetCode_Nov_1st_Week
LeetCode_Nov_3rd_Week