函数一(传址调用)
#include<stdio.h>
struct STU{char name[9];
char sex;
int score[2];};
void f(struct STU a[])
{struct STU b={"Zhao",'m',85,90};
a[1]=b;}
main()
{struct STU c[2]={{"Qian",'f',95,92},{"Sun",'m',98,99}};
f(c);
printf("%s,%c,%d,%d,",c[0].name,c[0].sex,c[0].score[0],c[0].score[1]);
printf("%s,%c,%d,%d\n",c[1].name,c[1].sex,c[1].score[0],c[1].score[1]);}
输出结果是Qian,f,95,92,Zhao,m,85,90(f函数有作用)
函数二(传值调用)
#include<stdio.h>
#include<string.h>
struct A
{int a;char b[10];double c;};
void f(strcut A t);
main()
{struct A a={1001,"ZhangDa",1908.0};
f(a);printf("%d,%s,%6.1f\n",a.a,a.b,a.c);}
void f(struct A t)
{t.a=1002;
strcpy(t.b,"ChangRong");t.c=1202.0;}
输出结果是1001,ZhangDa,1098.0(f函数无作用)
初学者表示已经要崩溃了,求大神解答简单点!不然我听不懂!
慕后森
撒科打诨