结构体变量的初始化
和其它类型变量一样,对结构体变量可以在定义时指定初始值。
实例
include
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
} book = {"C 语言", "RUNOOB", "编程语言", 123456};
int main()
{
printf("title : %s\nauthor: %s\nsubject: %s\nbook_id: %d\n", book.title, book.author, book.subject, book.book_id);
}
执行输出结果为:
title : C 语言
author: RUNOOB
subject: 编程语言
book_id: 123456