由于水平原因,博客大部分内容摘抄于网络,如有错误或者侵权请指出,本人将尽快修改

结构体:多种类型数据的集合体

结构体对象是由结构体成员变量组成的变量集合体。

结构体对象的定义格式和整型变量的定义格式是一样的:类型名+变量名。

结构体的数据类型名是“struct结构名”。结构体对象可以在定义的同时进行初始化,方法如同数组的初始化。

struct Books{
    const char* title;
    char author[50];
    char subject[100];
    int bookId;
}book={"C 语言", "RUNOOB", "编程语言", 123456};

struct 数组的使用

struct Books{
    const  char* title;
    char author[50];
    char subject[100];
    int bookId;
}book[10];
int main()
{
    for(int i=0;i<10;i++){
        book[i].title="1";
        strcpy(book[i].author,"1");
        printf("title : %s\nauthor: %s\nsubject: %s\nbook_id: %d\n", book[i].title, book[i].author, book[i].subject, book[i].bookId);
    }
    return 0;
}

struct 重载运算符号

 

struct Node{
    int id,num;
    int score;
    bool operator<(const Node& th)const{
        if(score!=th.score)return score<th.score;
        else
        return th.id!=id ?th.id<id:th.num<num;
    }
} node;

  

 

 

posted @ 2020-06-21 17:21  小纸条  阅读(508)  评论(0)    收藏  举报