第二个参数为空的 C 条件运算符 ('?') [英] C conditional operator ('?') with empty second parameter

查看:19
本文介绍了第二个参数为空的 C 条件运算符 ('?')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常是?"运算符的使用形式如下:

Typically the '?' operator is used in the following form:

A ? B : C

但是在 B = A 的情况下,我看到了以下缩写

However in cases where B = A I have seen the following abbreviation

A ? : C

这出人意料地有效.将第二个参数保留在(风格方面)更好,还是某些编译器无法处理这个问题?

This surprisingly works. Is it better to leave the second parameter in (style wise), or is their a chance certain compilers won't be able to handle this?

推荐答案

C语言不允许(据我所知),但是像gcc这样的编译器有快捷方式a?:c作为扩展.a?:ca?a:c 含义相同.

It is not permitted by the language C (as far as I know), but compilers such as gcc have the shortcut a?:c as an extension. a?:c means the same as a?a:c.

这篇关于第二个参数为空的 C 条件运算符 ('?')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆