I am currently using Visual Studios for class and needless to say I am having difficulty understanding pointers. I have created a program but does not seem to work right for me. I keep getting an assertion error after I click the function type that I want. I get a Debug assertion failed pop up error. Expression: result_pointer != nullptr. It says line 1558
int function1(int a,int b);
int function2(int a, int b);
int function3(int a, int b);
int(*p[3])(int x, int y);
int main()
{
int num1, num2;
int choice = 0;
p[0] = function1;
p[1] = function2;
p[2] = function3;
printf("Please enter two numbers: ");
scanf_s("%d", &num1);
scanf_s("%d", &num2);
printf("Which would you like to try (1 for Math, 2 for Subtraction, 3 for Multiplication): \n");
scanf_s("%d", choice);
int (*i) = &choice;
while (*i >= 0 && *i < 3) {
(p[*i])(num1,num2);
}
puts("Program execution compiled");
}
int function1(int a, int b)
{
int total;
total = a + b;
return total;
}
int function2(int a, int b)
{
int total;
total = a - b;
return total;
}
int function3(int a, int b)
{
int total;
total = a * b;
return total;
}
scanf_s("%d",choice), you need to pass a pointer, but instead you passed anint. In other words line 26 should bescanf_s("%d", &choice)printfthe outcome. Also, thewhileloop will never end. Thewhileshould beif.