Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » array of function pointer
array of function pointer [message #36149] Sat, 05 May 2012 13:08 Go to previous message
varu is currently offline  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;

}

 
Read Message
Read Message
Previous Topic: Form with OpenGL Display object
Next Topic: fills the DropList from VectorMap
Goto Forum:
  


Current Time: Fri May 10 20:39:25 CEST 2024

Total time taken to generate the page: 0.02369 seconds