撰寫程式:定義一個結構型別,可以存盤一個學生的總評成績和一個該結構型別的指標。輸入三個學生的總評成績到三個結構變數。讓第一個變數的指標型別的成員存盤第二個變數的地址,讓第二個變數的指標型別的成員存盤第三個變數的地址,讓第三個變數的指標型別的成員的值為NULL。然后定義一個函式,引數為一個結構體指標型別,輸出三個學生各自的總評成績。該函式在呼叫時的實參為第一個變數的地址。
然后我寫的代碼是:
#include <stdio.h>
struct studentinfo
{
int score;
struct studentinfo* next;
}st1,st2,st3;
void Print_Score(struct student *st1)
{
printf("st1.score = %d \n",st1->score);
printf("st2.score = %d \n",st1->next->score);
printf("st3.score = %d \n",st1->next->score);
}
int main()
{
st1.score =100;
st2.score = 98;
st3.score = 96;
st1.next = &st2;
st2.next = &st3;
st3.next = NULL;
Print_Score(&st1);
return 0;
}
然后DVC編譯器上面報錯,改了許久還是沒有改出來,求大佬解答!!!!!
uj5u.com熱心網友回復:
student 應該是studentinfouj5u.com熱心網友回復:
就是個鏈表嘛。printf("st3.score = %d \n",st1->next->score); ==》》printf("st3.score = %d \n",st2->next->score);
uj5u.com熱心網友回復:
#include <stdio.h>
struct studentinfo
{
int score;
struct studentinfo* next;
}st1,st2,st3;
void Print_Score(struct studentinfo *st1)
{
printf("st1.score = %d \n",st1->score);
printf("st2.score = %d \n",st1->next->score);
printf("st3.score = %d \n",st1->next->next->score);
}
int main()
{
st1.score =100;
st2.score = 98;
st3.score = 96;
st1.next = &st2;
st2.next = &st3;
st3.next = NULL;
Print_Score(&st1);
return 0;
}
供參考~
Print_Score函式的形參型別在哪里宣告的?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/46009.html
標籤:C語言
下一篇:小白求大佬幫忙看看錯哪了
