焦糖橙子 发表于 2021-8-7 10:36:07

S1E41课后题(宏定义问题)

1. 请补充下面代码,添加一个宏定义,让程序可以统计 COUNTS 参数的个数。
我用DEV有报错
D:\C语言程序设计与数据结构\S1E41\S1E41.cpp        expected ')' before 'Apple'
是说说我缺少括号?但是我看也没少啊。代码也是参考答案,为什么会这样啊?
代码如下:

#include <stdio.h>

#define ARGUMENTS(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, ...) A11
#define COUNTS(...) ARGUMENTS(FISHC, ## __VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

int main(void)
{
      printf("COUNTS()有 %d 个参数。\n", COUNTS());
      printf("COUNTS(1, 2, 3)有 %d 个参数\n", COUNTS(1, 2, 3));
      printf("COUNTS("Apple", "Banana", "Cat", "Dog")有 %d 个参数\n", COUNTS("Apple", "Banana", "Cat", "Dog"));

      return 0;
}

万千只cnm 发表于 2021-8-7 11:14:26

   printf("COUNTS()有 %d 个参数。\n", COUNTS());
      printf("COUNTS(1, 2, 3)有 %d 个参数\n", COUNTS(1, 2, 3));
    printf("COUNTS(""Apple"", ""Banana"", ""Cat"", ""Dog"")有 %d 个参数\n",COUNTS("Apple", "Banana", "Cat", "Dog") );
页: [1]
查看完整版本: S1E41课后题(宏定义问题)