Here's a simple example. Say you're tracking book sales. Every book has a name and a number of pages and so forth. So you set up a book struct like so:
Code:
struct book_base
{
char *name;
int num_pages;
};
Now, normally you'd set up array of struct book_base, one element for each book you're tracking. So say you had 3 books. You might do something like:
Code:
{
struct book_base books[3] =
{
{ "Book 1", 213 }, { "Book 2", 99 }, { "Book 3", 792 }
};
}
Now let's say you have 50 of each book and you want to track where they are. You could do something like this:
Code:
struct indiv_book
{
int sold; // 0 = not sold, still in store; 1 = sold
time_t sell_date;// 0 if not yet sold otherwise time_t value of when sold
struct book_base *book; // Pointer to book information
};
Then you might do something like:
Code:
{
struct indiv_book book[150]; // 50 each of 3 books
book[0].sold = 0; // Not sold yet
book[0].sell_date = 0; // Set to time(0) when sold
book[0].book = &books[1]; // This particular book is a "Book 2".
}
Then you could see the name of book[0] that you're tracking by doing:
printf("%s\n", book[0].book->name);
Or you could check how many pages book[0] has by looking at book[0].book->num_pages.
Clear as mud?