Home » Community » Newbie corner » array of function pointer
array of function pointer [message #36149] |
Sat, 05 May 2012 13:08 |
varu
Messages: 21 Registered: March 2012 Location: Bangalore,India
|
Promising Member |
|
|
hi
i am doing something similar as show below in c . can u please help me to do the same in u++
#include <stdio.h>
int sum(int a, int b);
int subtract(int a, int b);
int main(void)
{
p[0] = sum; // address of sum()
p[1] = subtract; // address of subtract()
int result;
int i = 2, j = 2, op;
printf("0: Add, 1: Subtract\n");
do {
printf("Enter number of operation: ");
scanf("%d", &op);
} while(op<0 || op>2);
result = (*p[op]) (i, j);
printf("%d", result);
return 0;
}
int sum(int a, int b)
{
return a + b;
}
int subtract(int a, int b)
{
return a - b;
}
|
|
|
Goto Forum:
Current Time: Wed Jun 05 04:12:25 CEST 2024
Total time taken to generate the page: 0.01920 seconds
|