If you remember our studies of structures and pointers, you will recall that if we have a structure with a pointer pointing to it, we can access any of the variables within the structure. In the next three lines of the program, we assign some silly data to the structure for illustration. It should comeas nosurprise toyouthat these assignment statements look just like assignments to statically defined variables.
In the next statement, we assign the value of "pet1" to "pet2" also. This creates no new data, we simply have two pointers to the same object. Since "pet2" is pointing to the structure we created above, "pet1" can be reused to get another dynamically allocated structure which is just what we do next. Keep in mind that "pet2" could have just as easily been used for the new allocation. The new structure is filled with silly data for illustration.
Finally, we allocate another block on the heap using the pointer "pet3", and fill its block with illustrative data.
Printing the data out should pose no problem to you since there is nothing new in the three print statements. It is left for you to study.
In the next statement, we assign the value of "pet1" to "pet2" also. This creates no new data, we simply have two pointers to the same object. Since "pet2" is pointing to the structure we created above, "pet1" can be reused to get another dynamically allocated structure which is just what we do next. Keep in mind that "pet2" could have just as easily been used for the new allocation. The new structure is filled with silly data for illustration.
Finally, we allocate another block on the heap using the pointer "pet3", and fill its block with illustrative data.
Printing the data out should pose no problem to you since there is nothing new in the three print statements. It is left for you to study.

