int(*f [])(int*)代表什么?

Cpt*_*ent 3 c

这是考试问题之一,目标是确定该课程的内容.我真的很困惑int (*f[])(int*) = {f1, f2, f2, f1 };.我教过它可能是一个数组,其元素是括号中函数的结果,这些结果是指向int的地址.

你能解释一下吗?

而且,该函数f[i++]进入的参数是什么

for (i=0; i<2; a += fx(f[i++], a));

问题:

int f2(int *p) { return *p-- + 2; }

int f1(int *q) { return ++*q; }

int fx(int (*pf)(int*), int q) {
    int t = q;
    while ((t = pf(&q)) % 2) q+=2;
    return t;
}

#include <stdio.h>

void main() {
    int a = 4, b = 3, *p = &b, i;
    int (*f[])(int*) = {f1, f2, f2, f1 };

    for (i=0; i<2; a += **fx(f[i++]**, a));
    printf("%d", a + *p);
}
Run Code Online (Sandbox Code Playgroud)

pmg*_*pmg 11

应用顺时针/螺旋规则

int (*f[])(int*)
      ^                f is

int (*f[])(int*)
      ^^^              f is an array

int (*f[])(int*)
    ^^^^^^             f is an array of pointers

int (*f[])(int*)
    ^^^^^^^....^       f is an array of pointers to functions


int (*f[])(int*)
    ^^^^^^^^^^^^       f is an array of pointers to functions
                       that accept a pointer to int

int (*f[])(int*)
^^^^^^^^^^^^^^^^       f is an array of pointers to functions
                       that accept a pointer to int and return a int value
Run Code Online (Sandbox Code Playgroud)