0
Why there is no parentheses when assigning a function to a function pointer
int (*op[4])(int, int); op[0] = add; op[1] = subtract; op[2] = multiply; op[3] = divide; printf("Enter two integers: "); scanf("%d%d", &x, &y); printf("Enter 0 to add, 1 to subtract, 2 to multiply, or 3 to divide: "); scanf("%d", &choice); result = op[choice](x, y); printf("\n %d", result); return 0; } int add (int x, int y) { return(x + y); }
2 odpowiedzi
+ 2
If you add parenthesis, then its becomes a call to that function, not as assignment according syntaxes..
So with parenthesis, it will call function and store returned value in op[n], Instead of storing function pointer (Hoping on equal compatibility in storage, if not, raise errors..)
so there is no need to add parenthesis in assignment..
+ 1
Jayakrishna🇮🇳 thanks a lot👊