#include struct animal { char* (*talk)(); void (*elongate)(struct animal*); int length; }; // After this typdef, we can say Animal instead of struct animal typedef struct animal Animal; char* squirreltalk(){ return "squirrelish chirp"; } void squirrelstretch(struct animal* us){ us->length += 2; } char *cattalk(){ return "meow"; } void catstretch(Animal* us){ us->length += 4; // Same as (*us).length += 4; } void try_out_animal(Animal *pet){ // We do not know if pet is a squirrel or a cat! printf("%s\n", pet->talk()); printf("Initial Length: %d\n", pet->length); pet->elongate(pet); printf("Final Length: %d\n", pet->length); } int main(){ Animal squirrel; squirrel.talk = squirreltalk; squirrel.elongate = squirrelstretch; squirrel.length = 10; // Different style, same result (this only works in C) struct animal cat = { .talk = cattalk, .elongate = catstretch, .length = 15 }; try_out_animal(&squirrel); try_out_animal(&cat); return 0; }