retagged by
315 views
3 votes
3 votes
#include <stdio.h>
void A() { printf("A");};
void B() { printf("B");};
void C() { printf("C");};
void D() { printf("D");};
int main() {
  void (*P[4])() = {A,B,C,D};
  for(int i=0;i<4;i++) (*(i+P))();
}
retagged by

1 Answer

Best answer
3 votes
3 votes

void (*P[4])() = {A,B,C,D};

P is an array of pointers to functions and the size of the array is 4. The array is initialized to point to the functions A, B, C, D.

        

P Pointer to A
P+1 Pointer to B
P+2 Pointer to C
P+3 Pointer to D

In the for() loop each function is called.

So, the output is ABCD.

selected by

Related questions