samedi 28 mars 2015

Structure with array of function pointer




#include <stdio.h>
void getSum();
void getDifference();
typedef void (*functionPtr)();
// assign the function's address
functionPtr arrayFp[2] = {getSum, getDifference};
struct true{
int a;
int b;
functionPtr arrayFp[2];//syntax may be wrong
}w={5,6,arrayFp[0]};
int main()
{w.arrayFp[0]; //syntax is wrong
return 0;}
void getSum(){
printf("I am the greatest");}
void getDifference(){
printf("I am not the greatest");}


I am trying to access the arrayFp of type functionPtr that contains the address of function getSum and getDifference.I don't know the syntax correctly .Please point out the errors in the code and syntax for accessing the array inside the structure.




Aucun commentaire:

Enregistrer un commentaire