Question: //Note: This is a code in C..... (*fun_ptr_arr[choice])(a, b);// I got an error in this line and I dont know why! #include float a, b;
//Note: This is a code in C..... (*fun_ptr_arr[choice])(a, b);// I got an error in this line and I dont know why!
#include
float a, b;
int choice;
void add()
{
printf("Addition is %f ", a+b);
}
void subtract( )
{
printf("Subtraction is %f ", a-b);
}
void multiply( )
{
printf("Multiplication is %f ", a*b);
}
void divide( )
{
printf("Division is %f ", a/b);
}
int main(void)
{
//float a, b;
void (*fun_ptr_arr[]) = {add, subtract, multiply, divide}; // array of function pointers
unsigned int ch, a=0.0 , b=0.0;
printf("Enter Choice: 1 for add, 2 for subtract, 3 for multiply, 4 for divide ");
scanf("%d", &choice);
if (choice > 4 ) return 0;
if (choice < 1 ) return 0;
printf("enter the first number ");
scanf("%f",&a);
printf("enter the second number ");
scanf("%f",&b);
(*fun_ptr_arr[choice])(a, b);// I got an error here
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
