struct Person{
char name[22];
bool sex;
int age;
double score;
};
typedef struct
{
char title[50];
char author[50];
char subject[100];
int book_id;
}Books;
void printPerson(struct Person person){
cout << "name = " << person.name << endl;
cout << "sex = " << person.sex << endl;
cout << "age = " << person.age << endl;
cout << "score = " << person.score << endl;
}
void printPerson2(struct Person *person){
cout << "name = " << person->name << endl;
cout << "sex = " << person->sex << endl;
cout << "age = " << person->age << endl;
cout << "score = " << person->score << endl;
}
int main() {
count = 5;
write_extern();
Person p1;
Person p2;
Books books;
strcpy(books.author,"jack");
strcpy(p1.name,"tom");
p1.sex = false;
p1.age = 11;
p1.score = 89.5;
strcpy(p2.name,"tom2");
p2.sex = true;
p2.age = 22;
p2.score = 77.5;
printPerson(p1);
printPerson2(&p2);
return 0;
}
C++学习笔记5----结构体
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...