C++学习笔记5----结构体

2017-06-22  本文已影响14人  ChineseBoy
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;
}
上一篇下一篇

猜你喜欢

热点阅读