三元条件 ?: objective c 示例

ternary conditional ?: objective c example

我是 objective c 的新手。以下代码来自我搜索过的 GCC:

int a = b ?: c;

这相当于

if (!b) //if b variable its not zero
{
a=b;
}
else
{
a=c;
}

我想的对吗?

比如我声明了默认的bc变量:

int b = 0;
int c = 1;

int a = b ?: c;

a = 1 in this case. Otherwise, if b is not zero a will take b as a result.

它将等于:

if (!b) {
    a = c;
} else {
    a = b;
}