Last active
February 22, 2018 16:54
-
-
Save ethagnawl/a59a3e395499fb556ea2715ff6361ae4 to your computer and use it in GitHub Desktop.
C function pointer example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef void (*thing_sayer)(char *person); | |
void say_hello(char *person) { | |
printf("Hello, %s!\n", person); | |
} | |
void say_goodbye(char *person) { | |
printf("Goodbye, %s!\n", person); | |
} | |
void say_something(thing_sayer say_thing, char *person) { | |
say_thing(person); | |
} | |
int main() { | |
char person[] = "Pete"; | |
say_something(say_hello, person); | |
say_something(say_goodbye, person); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment