說明:用const來防止誤操作。
#include <iostream>
using namespace std;
#include<string>
struct Student
{
string name;
int age;
int score;
};
void printStudents(const struct Student *s1)
{
//s1->age = 19;//編譯報錯,因爲形參有const修飾所以不可修改,只能打印(讀)
cout << s1->age << s1->name<<s1->score<<endl;
}
int main()
{
struct Student s1 = { "小紅",14,67 };
printStudents(&s1);
system("pause");
return 0;
}