C指令说明

| 谁能解释以下说明:
int *c[10];

char *(**n)(void);

float *(**r(void))[6];


short *(**v(void))(int);


long *(*(*(*z)(void))[7])(void);
    
已邀请:
http://www.cdecl.org/将解释所有这些声明。 C Right-Left规则解释了如何很好地阅读C碎片。还有很多其他资源可用,特别是在这个问题上。     
由于这是您的家庭作业,您不会通过我告诉您的所有内容而学到这;)但是,一个提示。您可以创建并传递指向C中函数的指针,而不仅仅是变量。 除了第一个示例外,所有函数的参数都是函数指针的原型。 假设我们有一个测试颜色的库,我们可能希望允许库的用户提供获取颜色名称的自定义方法。我们可以为用户定义一个结构,以传递包含我们可以调用的回调的信息。
struct colour_tester {
  char *(*colour_callback)(void);    
}

// test the user\'s function if given
void run_test(struct colour_tester *foo ){
  // use the callback function if set
  if ( foo->colour_callback != NULL ){
    char * colour = (*foo->colour_callback)();
    printf( \"colour callback returned %s\\n\", colour );
  }
}
然后,库的用户可以自由定义这些回调函数的实现,并将它们作为函数指针传递给我们。
#include <colour_tester.h>

char * get_shape_colour(){
  return \"red\";
}

int main ( int argc, char** argv ) {
  // create a colour tester and tell it how to get the colour
  struct colour_tester foo;
  foo.colour_callback = &get_shape_colour;
  run_test( &foo );
}
我让您去解决那些带有* s额外数字的问题。     

要回复问题请先登录注册