Code:
#include <stdio.h>
int add(int x, int y); /* declare function */
int main() {
int x=6, y=9;
int (*ptr)(int, int); /* declare pointer to function*/
ptr = add; /* set pointer to point to "add" function */
printf("%d plus %d equals %d.\n", x, y, (*ptr)(x,y));
/* call function using pointer */
return 0;
}
int add(int x, int y) { /* function definition */
return x+y;
}
in this line
Code:
int (*ptr)(int, int);
i can see that they are building an int type pointer but i can see here the name
of the function "add" which we are using ,plus this makes no sense (int, int);
usually when we build a function we write some names to the input integers like
add(int x,int y)
in this line:
they treat add as if it was a simple variable and the is no &
i think it should look like
Code:
*ptr = &add(int x,int y);
??