Page 121 - 6437
P. 121
return 0;
}
void printBook( struct Books book )
{
printf( "Book title : %s\n", book.title);
printf( "Book author : %s\n", book.author);
printf( "Book subject : %s\n", book.subject);
printf( "Book book_id : %d\n", book.book_id);
}
When the above code is compiled and executed, it produces the following result:
Book title : C Programming
Book author : Nuha Ali
Book subject : C Programming Tutorial
Book book_id : 6495407
Book title : Telecom Billing
Book author : Zara Ali
Book subject : Telecom Billing Tutorial
Book book_id : 6495700
Pointers to Structures
You can define pointers to structures in the same way as you define pointer to any other
variable:
Now, you can store the address of a structure variable in the above-defined pointer
struct Books *struct_pointer;
variable. To find the address of a structure variable, place the ‘&’ operator before the structure's
name as follows:
struct_pointer = &Book1;
To access the members of a structure using a pointer to that structure, you must use the ->
operator as follows:
struct_pointer->title;
Let us rewrite the above example using structure pointer.
#include <stdio.h>
124