I need to understand why we can call a pointer to a function in C without * as if we are calling a regular function (which may confuse a reader to the program since he may search for a function with this name and would not find it)
#include <stdio.h>
int sum(int , int);
int main(void){
int a, b, total;
int (*ptr_sum)(int x, int y)=sum;
printf("Enter a:");
scanf("%d", &a);
printf("Enter b:");
scanf("%d", &b);
total=(*ptr_sum)(a, b); //************line 1
total=ptr_sum(a, b); //************line 2
printf("The total = %d\n", total);
return(0);
}
int sum(int m, int n) {
return m+n;
}
On line 1 we called the function pointer using the *
operator. On line 2 we called it once again but without *
, just as if it were a regular function.
Why? Why both are the same?