Selasa, 18 Desember 2018

STRUCTURE

Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book −
  • Title
  • Author
  • Subject
  • Book ID

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 −
struct Books {
   char  title[50];
   char  author[50];
   char  subject[100];
   int   book_id;
} book;  

Accessing Structure Members

To access any member of a structure, we use the member access operator (.). The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. You would use the keyword struct to define variables of structure type.
Ex : student.number, book1.title

Tidak ada komentar:

Posting Komentar