结构体指针地址和值的问题
#include<stdio.h>#include<malloc.h>
typedef struct
{
int num[15];
char name[15];
float score[3];
double aver;
double sum;
}Stu;
int input (Stu* p)
{
int n, i, j;
printf("please input N students information!\n");
scanf("%d", &n);
p=(Stu* )malloc(n * sizeof(Stu));
for (i = 0; i < n ; i++, p++)
{
printf("input score of student%d\n", i + 1);
scanf("%d%s",&p[i].num, p[i].name);printf("%d %s ",*p[i].num, p[i].name); 一直都没想明白。输入&p[i].num,为啥输出的时候要加*号才是p[i].num的值。p[i].name则不用,因为他是字符串
for (j = 0; j < 3; j++)
{scanf("%f", &p[i].score[j]);printf("%7.2f", p[i].score[j]);} 而这里的p[i]p[j]也要&,因为它是浮点数。为啥输出就不需要加*,有点不明白。麻烦大牛帮忙解析下。不然没法继续做题啊。谢谢!!!
}
return n;
}
int main ()
{
int n;
Stu St, *Sp;
n=input(&St);
//Handle(Sp, n);
}