C 练习实例87
题目:回答结果(结构体变量传递)。
程序分析:无。
实例
// Created by www.runoob.com on 15/11/9.
// Copyright © 2015年 菜鸟教程. All rights reserved.
//
#include<stdio.h>
struct student
{
int x;
char c;
} a;
int main()
{
a.x=3;
a.c='a';
f(a);
printf("%d,%c",a.x,a.c);
}
f(struct student b)
{
b.x=20;
b.c='y';
}
输出结果为:
3,a
C 语言经典100例
cathy
rug***0241024@126.com
参考地址
1. 结果为:3,a, 这是默认函数参数是按值传递(返回值不会改变)
2. 要想改变,必须改变参数的传递方式为按址传递;
3. 具体代码为:
#include<stdio.h> struct student { int x; char c; } a; /* 函数声明 */ struct student f(struct student *b); int main() { a.x=3; a.c='a'; f(&a); printf("%d,%c",a.x,a.c); return 0; } struct student f(struct student *b) { b ->x = 20; b->c ='y'; }cathy
rug***0241024@126.com
参考地址