2
Considering the code below, I wonder why the second printf of the Lealuno procedure does not print correctly?
#define MAX 3
typedef struct aluno{
int matricula;
float notas[2];
} Aluno ;
int t=1;
void LeAluno(Aluno *Param){// com ponteiro
t++;
Param->matricula=10*t;
Param->notas[0]=20*t;
printf("\n 1 %f",(*Param).notas[0]);
printf("\n 2 %f",*(Param+sizeof(int)) ); //size of int matricula;
Param->notas[1]=30*t;
}
void main(){
int i;
Aluno Turma[MAX];
for(i=0; i< MAX; i++)
LeAluno(&Turma[i]);
}
Printfs are: printf(" n 1 %f",(Param). notes[0]); printf(" n 2 %f",(Param+sizeof(int)) );
– elder
Explain what you want to show with prints
– Jorge B.
To access members of a structure via a pointer you can use the shortcut
->
--(*Param).notas[0]
is the same asParam->notas[0]
– pmg