C function to call 5 different functions
-
I've been recently asked in an interview to write down a function that takes a char and returns void, and using this char the function would call between 5 different functions, Beside I have to write this function in three different ways. I figured out two, but failed to come with the third. My two functions were : 1- using switch on the coming argument 2 - using if else statements ,, can some 1 deduce the third , this is bugging me.
-
I've been recently asked in an interview to write down a function that takes a char and returns void, and using this char the function would call between 5 different functions, Beside I have to write this function in three different ways. I figured out two, but failed to come with the third. My two functions were : 1- using switch on the coming argument 2 - using if else statements ,, can some 1 deduce the third , this is bugging me.
Here's an idea: Use the
char
as an array index for an array of function pointers.The difficult we do right away... ...the impossible takes slightly longer.
-
Here's an idea: Use the
char
as an array index for an array of function pointers.The difficult we do right away... ...the impossible takes slightly longer.
alright I like this one :thumbsup::thumbsup: