We still have a funny looking construct at the beginning of the "malloc" function call. That is called a "cast". The "malloc" function returns a block with the pointer pointing to it being a pointer of type "char" by default. Many times, if not most, you do not want a pointer to a "char" type variable, but to some other type. You can define the pointer type with the construct given on the example line. In this case we want the pointer to point to a structure of type "animal", so we tell the compiler with this strange looking construct. Even if you omit the cast, most
compilers will return a pointer correctly,
give you a warning, and go on to produce a working program. It is better programming practice to provide the compiler with the cast to prevent getting the warning message.
compilers will return a pointer correctly,
give you a warning, and go on to produce a working program. It is better programming practice to provide the compiler with the cast to prevent getting the warning message.