0

I was looking into simple source code. and found this line

 int (*pfds)[2];

does it means pointer to function similar to

     void (*fun_ptr)()[2] = &fun; 

which I think is array of pointer to function fun(void)

user786
  • 3,902
  • 4
  • 40
  • 72

2 Answers2

1

int (*pfds)[2];----> pfds is a pointer to an array of 2 elements.

void (*fun_ptr)()[2]----> Declare fun_ptr as pointer to function returning array of 2 elements of void. But it is invalid. Since, in C, function returning array is not allowed.

void* (*fun_ptr)() -----> declare fun_ptr as pointer to function returning, pointer to void. This is valid. This is what you need, if you want to return an array of type void.

Krishna Kanth Yenumula
  • 2,533
  • 2
  • 14
  • 26
0

int (*pfds)[2]; is a pointer to an array with two elements.

The parentheses are there because int *pfds[2]; would be an array of two pointers, as in char *argv[] being an array of char pointers (i.e. strings).

A function pointer void (*fun_ptr)() has a second set of parentheses which is used for the argument list: int (*add)(int x, int y).

It doesn't seem void (*fun_ptr)()[2] or void *fun_ptr() would be valid.

user66554
  • 558
  • 2
  • 14