This is my program in C:
#include <stdio.h>
char const* voice(void){
return "hey!";
}
int main(){
const char* (*pointer)(void);
pointer = &voice;
printf ("%s\n", *pointer); // check down *
return 0;
}
What am I doing wrong?
You need to call the function pointers, ie use parenthesis:
#include <stdio.h>
char const* voice(void){
return "hey!";
}
int main(){
const char* (*pointer)(void);
pointer = &voice;
printf ("%s\n", pointer());
// ^^^^^^^^^
return 0;
}
* isn't needed for function pointers. (neither is &)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With