gpt4 book ai didi

c - C语言中的switch语句

转载 作者:太空宇宙 更新时间:2023-11-04 07:14:28 24 4
gpt4 key购买 nike

下面的 switch 语句是否正确?我的意思是我可以在一个 switch case 语句中使用常量和字 rune 字吗?它在代码中有效,但我是从良好实践的角度出发问的。

switch(arg[1]) {
case '4':
printf("value is 4\n");
break;
case '6':
printf("value is 6\n");
break;
case 'M':
printf("value is M\n");
break;
default:
break;
}

最佳答案

It works in code but I am asking from good practices standpoint.

是的,可以在switch 语句中使用char 变量和常量。这很常见,例如 to process command line arguments . char 是一种整数类型,switchchar 以及任何其他整数类型一样适用。

关于c - C语言中的switch语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26024141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com