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

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、编译指令:预处理,宏定义。建立自己的数据类型:结构体,联合体,动态数据结构。逻辑运算符。函数递归调用。 编译四...
    lain355阅读 2,720评论 0 0
  • 完成效果图。 先把对象的大概轮廓勾出来。 把对象的线稿描黑,画面上元素比较多,要注意用线的区别。 绘制整体的暗部。...
    紫草思雨阅读 1,703评论 1 7
  • (´・ω・`) 逐渐发现和别人的交往,不应该像过去一样,或多或少有二元的想法【交心or客套】。交往的模式与需求有很...
    霁青阅读 1,189评论 0 0
  • 9月3日咖啡冥想 好种子 1、今天小姨家的表妹的二宝满月,我和妈妈、弟弟去祝贺,妈妈和姊妹们又一次聚会,妈妈共有八...
  • 因为这次我没有和朋友们一起出来玩,所以我在来三亚前自己想象了很多种偶遇的场景,虽然遇到的几率很小,很小。 ...
    李庭语阅读 1,410评论 0 0