輸出結果第二個數報錯
為什么輸出的是90,25775849394
而不是90,98呀?
#include<stdio.h>
struct Student
{
? ? int math;
? ? int English;
};
int main()
{
? ? struct Student s[50];
? ? s[49].math=90;
? ? s[49].English=98;
? ? printf("%d,%d\n",s[49]);
? ? return 0;
}
為什么輸出的是90,25775849394
而不是90,98呀?
#include<stdio.h>
struct Student
{
? ? int math;
? ? int English;
};
int main()
{
? ? struct Student s[50];
? ? s[49].math=90;
? ? s[49].English=98;
? ? printf("%d,%d\n",s[49]);
? ? return 0;
}
2022-09-10
舉報
2023-03-11
c++是沒有print的!你應該是學過python的,python用的是print;而c++用的是cout。
如果想要運行,printf("%d,%d\n",s[49]);應該改為:
cout << s[49];或 cout << s[49] << endl; 或cout << s[49] << " ";
第一個是語句結束沒有任何其它內容,第二個是語句結束后換行,最后一個是空格
2022-09-18
//你的輸出錯誤了,s[49]是Student這個結構體,而不是里面數據的值 //第一個輸出結果是90,是因為取址在這個結構體的開頭,也就是s[49].math這個4字節內存的地址 //雖然這可以獲取math的數值但是你應該使用s[49].math來保證代碼魯棒性更高(不容易出bug) //你第一個%d對應的是math的值,第二次%d卻沒有對應,所以第二次輸出也就是垃圾數據了(毫無意義的一串數據) //你應該這樣,前一個%d對應s[49].math,后一個對應s[49].English printf("%d,%d\n",s[49].math,s[49].English);