当前位置:网站首页>结构体传参-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 函数哪个好些?
函数传参的时候,参数是需要压栈,会有时间和空间上的系统开销。
如果传递一个结构体对象的时候,结构体过大,参数压栈的的系统开销比较大,所以会导致性能的下降。
所以,结构体传参的时候,要传结构体的地址。
边栏推荐
- [English learning][sentence] good sentence
- Golang environment variable settings (2)--GOMODULE & GOPROXY
- MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification
- 典型CCN网络——efficientNet(2019-Google-已开源)
- An abstract class, internal classes and interfaces
- MNIST Handwritten Digit Recognition - Lenet-5's First Commercial Grade Convolutional Neural Network
- 卷积神经网络入门详解
- LeetCode_22_Apr_4th_Week
- 代码庆端午--粽你心意
- LeetCode_Dec_1st_Week
猜你喜欢
Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
Deep learning, "grain and grass" first--On the way to obtain data sets
集合---ArrayList的底层
IDEA创建Servlet步骤
详解近端策略优化
MNIST Handwritten Digit Recognition - Lenet-5's First Commercial Grade Convolutional Neural Network
第一章 绪论
LeetCode_Nov_5th_Week
【五一专属】阿里云ECS大测评#五一专属|向所有热爱分享的“技术劳动者”致敬#
Copy Siege Lion's Annual "Battle" | Review 2020
随机推荐
题目1000:输入两个整数a和b,计算a+b的和,此题是多组测试数据
MNIST手写数字识别 —— 基于Mindspore快速构建感知机实现十分类
第一章 绪论
MNIST Handwritten Digit Recognition - From Perceptrons to Convolutional Neural Networks
LeetCode_Nov_5th_Week
LeetCode_Dec_1st_Week
基于asp.net的法律援助平台的设计与实现(附项目链接)
yoloV5 使用——训练速度慢,加速训练
MNIST手写数字识别 —— 从二分类到十分类
浅谈外挂常识和如何防御
MNIST手写数字识别 —— ResNet-经典卷积神经网络
bind()系统调用的用处
集合--LinkedList
Question 1000: Input two integers a and b, calculate the sum of a+b, this question is multiple sets of test data
LeetCode_22_Apr_2nd_Week
通用解决端口占用问题
第二章 STA相关概念
CAS无锁队列的实现
The Unity of ML - agents interpret parameter Settings
arm学习-1-开发板