【程序源代码】:
结构体指针作函数参数#include <stdio.h>
struct stu
{
int num;
char name[10];
float score[3];
}; //唉,此程序犯的唯一错误,少了分号;
void add10(struct stu st2)
{
int i;
for(i=0; i<3; i++)
{
if(st2.score[i]<60)
st2.score[i] += 10;
}
printf("NO.:%d\nName:%s\nScore:%.2f, %.2f, %.2f\n", st2.num, st2.name, st2.score[0],st2.score[1],st2.score[2]);
}
void main(void)
{
struct stu st1 = {13, "Mili", 99.50,59.69, 58.80};
add10(st1);
}
/*VC++6.0中执行结果:
-------------------------
NO.:13
Name:Mili
Score:99.50, 69.69, 68.80
-------------------------
*/
#include <stdio.h>
struct stu
{
int num;
char name[10];
float score;
};
void list(struct stu *p)
{
p->score+=0.31;
printf("NO.:%d\tName:%s\tScore:%.2f\n", (*p).num, p->name, p->score);
}
void main(void)
{
struct stu st1 = {13, "Mili", 99.69};
list(&st1);
printf("NO.:%d\tName:%s\tScore:%.2f\n", st1.num, st1.name, st1.score);
}/*
------------------------------------
NO.:13 Name:Mili Score:100.00
NO.:13 Name:Mili Score:100.00------------------------------------
*/