When I initialize function pointers in one take, like below, it does not work.
ptr[3]={add, subtract, multiply};
This gives:
[Error] expected expression before '{' token
However, one-by-one initialization works. Why is this?
//array of function pointers
#include<stdio.h>
void add(int a, int b){
printf("%d\n", a+b);
}
void subtract(int a, int b){
printf("%d\n", a-b);
}
void multiply(int a, int b){
printf("%d\n", a*b);
}
int main(){
void (*ptr[3])(int, int);
//ptr[3]={add, subtract, multiply}; this initialization does not work
//but this works
ptr[0]=add;
ptr[1]=subtract;
ptr[2]=multiply;
ptr[2](3,5); //15
}