I have a pointer to a function returning a const char pointer. My question is how to print the pointer and then also the object (the string itself) referenced by the pointer(s).
Here is the code:
#include <stdio.h>
char const *func(void)
{
printf("Printed func string.\n");
return "Pointed func string.\n";
}
int main(void) {
char const *(*fp)(void) = func;
/*print statements here*/
return 0;
}
I get either a ISO C forbids conversion of function pointer to object pointer type
or some undefined behavior.
EDIT:
int main(void) {
char const *(*fp)(void) = func;
unsigned char *p = (unsigned char *)&fp;
/*print statements here*/
printf("The: %p\n",(char *) p);
return 0;
}
OUTPUT: 0x7fff36753500
Is not correct.