Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invoking function from the 2d array of function pointers

#include <stdio.h>

void test1(){ printf("test1\n"); }
void test2(){ printf("test2\n"); }
void test3(){ printf("test3\n"); }
void test4(){ printf("test4\n"); }

void (*hv_ptr[2])() = {test1,test2};
void (*dev_ptr[2])() = {test3,test4};

void (**ptr[2])() = {hv_ptr, dev_ptr};

int main() {

   ptr[0][0];
   ptr[0][1];
   ptr[1][0];
   ptr[1][1];

   return 0;
}

I have declared the array of pointers to function pointers. But with this code, functions are not getting called. Kindly let me know what is going wrong here.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ptr is an array of pointers to pointers to functions, so ptr[0] is a pointer to a pointer to a function, so ptr[0][0] is a pointer to a function.

Thus, in the expression statement ptr[0][0];, the expression is just a pointer to a function. It does not contain a function call.

ptr[0][0](); is a call to the function pointed to by ptr[0][0].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading