objective-c - 你怎么称呼在有条件的情况下做作业?

标签 objective-c c conditional-statements variable-assignment terminology

在条件中做赋值有特殊的名称吗?这是我在 C 中询问的示例:

// Assume a and b have been previously defined and are compatible types
if( (a = b) ) {  // <- What do you call that?
  //do something
}

我和我的几个 friend 确信它有一个名字,其他一些人也同意有一个名字,但我们到处都找不到。这里有人听过这个词吗?

最佳答案

假设赋值是有意的,对此没有特殊的名称。 C 语言规范对 if 语句的控制表达式提出了非常弱的要求:

6.8.4.1-1: The controlling expression of an if statement shall have scalar type.

赋值表达式满足这个要求,只要ab 是标量。对这个赋值的结果执行与零的隐式比较:

6.8.4.1-2: In both forms, the first substatement is executed if the expression compares unequal to 0. In the else form, the second substatement is executed if the expression compares equal to 0.

请注意,编译器在看到这样的赋值时会发出警告,因为缺少第二个 = 是常见的错误来源。 You can prevent these warnings using parentheses, as described in this Q&A .

关于objective-c - 你怎么称呼在有条件的情况下做作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46816589/

相关文章:

c - 如何在 ANSI C 中定义 NaN 值?

python - 在条件语句中声明变量有问题吗?

amazon-web-services - CloudFormation 格式错误 - "YAML not well-formed. (line 249, column 21)"

php - MySQL WHERE 条件是否将括号视为与 PHP 相同?

ios - Firebase 查询 - 查找包含字符串的子项目

ios - 通过索引获取 NSDictionary 键?

ios - TableView 不可见时未调用 cellForRowAtIndexPath

C Unix套接字编程,确保读/写字节数?

C 传递和指针

ios - Objective-c 从另一个 View Controller 重新加载 TableView