fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int MAX_NAME = 16;
  6.  
  7. struct Student {
  8. char name[MAX_NAME + 1];
  9. int scoreJapanese;
  10. int scoreMath;
  11. int scoreEnglish;
  12. };
  13.  
  14. void Show(const Student& s) {
  15. cout << "名前:" << s.name << endl;
  16. cout << "国語:" << s.scoreJapanese << endl;
  17. cout << "数学:" << s.scoreMath << endl;
  18. cout << "英語:" << s.scoreEnglish << endl;
  19. }
  20.  
  21. int main(void) {
  22. Student student[] = {
  23. {"aa",73,98,86},{"bb",64,45,40},{"cc",76,78,69}
  24.  
  25. };
  26.  
  27. cout << "sizeof(Student):" << sizeof(Student) << endl;
  28. cout << "sizeof(student):" << sizeof(student) << endl;
  29.  
  30. int size = sizeof(student) / sizeof(Student); // wakarimasen
  31. cout << "sizeof(student)/sizeof(Student):" << size << endl;
  32.  
  33. for (int i = 0; i < size; ++i) {
  34. Show(student[i]);
  35. }
  36.  
  37.  
  38. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
sizeof(Student):32
sizeof(student):96
sizeof(student)/sizeof(Student):3
名前:aa
国語:73
数学:98
英語:86
名前:bb
国語:64
数学:45
英語:40
名前:cc
国語:76
数学:78
英語:69