Hi,
I'm reading one article about function pointers and I found this simple code:
Code:
#include <stdio.h>
typedef int (*pFunc) (int, int);
int sum (int, int);
int diff (int, int);
int main ( void )
{
pFunc pfArr[2];
pfArr[0] = ∑ /* correct way*/
/*pfArr[0] = sum; Possible incorrect way ???*/
pfArr[1] = &diff;
printf("%d",pfArr[0](2,3));
printf("%d",(*pfArr[0])(2,3)); /*correct way*/
return 0;
}
int sum (int a, int b)
{
return a + b;
}
int diff (int a, int b)
{
return a - b;
}
I read there about "correct ways" to call function through function pointer.
I tried both solutions and both works fine.
Code:
printf("%d",pfArr[0](2,3));
printf("%d",(*pfArr[0])(2,3)); /*correct way*/
What I'm not sure is whether both solutions are valid according to the Standard. Please, can you comment this
Thanks
- Micko