Gaining Access to Structure Members

A structure is like a "superarray," in which one element can be char, the next element float, and the next an int array. You can access the individual elements of an array by using a subscript. How do you access individual members of a structure? Use a dot (.), the structure member operator. For example, libry.value is the value portion of libry. You can use libry.value exactly as you would use any other float variable. Similarly, you can use libry.title exactly as you would use a char array. Therefore, the program uses expressions like

gets(libry.title);

and

scanf("%f", &libry.value);

In essence, .title, .author, and .value play the role of subscripts for a book structure.

Note that although libry is a ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.