Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer to function in C

Tags:

c

pointers

What is the difference between the following two statements?

char *(*myfunc1)(char*, int)
char *myfunc2(char*, int)

I know that the second statement defines a function which receives a pointer to char and an int and returns a pointer to char. I also know that char (*myfunc2)(char*, int), would return a char. What does the extra * mean in the first statement?

like image 633
Tudor Ciotlos Avatar asked Jan 31 '26 19:01

Tudor Ciotlos


1 Answers

the first one defines a pointer to a function, the second one is a function....

so that you could do ... myfunc1 = myfunc2

whenever you see what looks like a function, but the name of the function is in brackets with a * like void (*blah)( void ) it means you are defining a pointer to a function.

like image 63
Keith Nicholas Avatar answered Feb 03 '26 07:02

Keith Nicholas