标签:对象 定义 turn author bsp 变量 printf sub 初始化
结构体对象是由结构体成员变量组成的变量集合体。
结构体对象的定义格式和整型变量的定义格式是一样的:类型名+变量名。
结构体的数据类型名是“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;
标签:对象 定义 turn author bsp 变量 printf sub 初始化
原文地址:https://www.cnblogs.com/clarencezzh/p/13173199.html