Defining A Structure
Defining A Structure
To define a structure, you must use the struct statement. The struct
statement defines a new data type, with more than one member. The
format of the struct statement is as follows −
member definition;
member definition;
...
member definition;
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
} book;
#include <stdio.h>
#include <string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
int main( ) {
/* book 1 specification */
Book1.book_id = 6495407;
/* book 2 specification */
Book2.book_id = 6495700;
return 0;
When the above code is compiled and executed, it produces the following
result −
Book 1 title : C Programming
Book 1 author : Nuha Ali
Book 1 subject : C Programming Tutorial
Book 1 book_id : 6495407
Book 2 title : Telecom Billing
Book 2 author : Zara Ali
Book 2 subject : Telecom Billing Tutorial
Book 2 book_id : 6495700