C语言经典例87-结构体变量传递

1 题目

结构体变量传递,验证结构体在函数参数中值传递的方式

2 分析

结构体在函数参数中传递依旧是值传递。

3 实现

#include <stdio.h>
 
struct student {
    int x;
    char c;
} a;
 
void func(struct student b)
{
    b.x = 333333;
    b.c = 'b';
}

int main()
{
    a.x = 3;
    a.c = 'a';
    func(a);
    printf("%d, %c", a.x, a.c);
}

4 运行结果

3, a
发布了125 篇原创文章 · 获赞 199 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/syzdev/article/details/104429456
今日推荐