Frankly, you will do best to defer trying to achieve polymorphism in C until you are no longer a newbie at programming in C.
Your code is dubious (it doesn't compile!). That should be void (*al)(void);
in your main
and you should arguably include the void
in the argument lists of tripple
and square
. You don't need the &
in front of the function names in the assignments to al
, though I don't think it does any actual harm. (Beware though; there is a difference between using an array name and the address of an array name! That is: char a[10]; char *s = a; char (*t)[10] = &a;
) You should also include a newline at the end of each message in each of these functions. Newlines at the beginning of a message are often (but not always) indicative of problems. Sometimes, it is OK to omit the newline at the end of a message, but not very often.
Any polymorphism implemented in C will use function pointers. But you should not be trying to implement polymorphism in C until you are comfortable using function pointers without attempting polymorphism. I suppose it could be said to be 'learning to swim by jumping in at the deep end', but you'd do better to learn a language like C++ that supports polymorphism than trying to do it in C which doesn't really do so.