鱼C论坛

 找回密码
 立即注册
查看: 2364|回复: 9

C语言三个数输出最大值,求助

[复制链接]
发表于 2021-10-16 11:30:45 | 显示全部楼层


    此句用 gcc 10.2.0 编译出错
  1. int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c);
复制代码

    具体信息为:
  1. D:\00.Excise\C>g++ -o x x.c
  2. x.c: In function 'int max(int, int, int)':
  3. x.c:3:37: error: expected identifier before '(' token
  4.     3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
  5. ;
  6.       |                                     ^
  7. x.c:3:30: error: named return values are no longer supported
  8.     3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
  9. ;
  10.       |                              ^~~~~~
  11. x.c:6:9: error: declaration of 'int a' shadows a parameter
  12.     6 |     int a, b, c;
  13.       |         ^
  14. x.c:3:13: note: 'int a' previously declared here
  15.     3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
  16. ;
  17.       |         ~~~~^
  18. x.c:6:12: error: declaration of 'int b' shadows a parameter
  19.     6 |     int a, b, c;
  20.       |            ^
  21. x.c:3:20: note: 'int b' previously declared here
  22.     3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
  23. ;
  24.       |                ~~~~^
  25. x.c:6:15: error: declaration of 'int c' shadows a parameter
  26.     6 |     int a, b, c;
  27.       |               ^
  28. x.c:3:27: note: 'int c' previously declared here
  29.     3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
  30. ;
  31.       |                       ~~~~^

  32. D:\00.Excise\C>
复制代码

        必须改为
  1. int max(int a, int b, int c) {return (a > b && a > c ? a : b > c ? b : c);}
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-3 02:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表