语句while(E);中的表达式E等价于E!=0
时间: 2023-11-25 13:05:51 浏览: 114
不完全正确。
语句 `while (E);` 中的表达式 E 是一个条件表达式,其值为 0 或 1。当 E 的值为 0 时,循环终止;当 E 的值为 1 时,循环继续执行。因此,语句 `while (E);` 只是一个死循环,它会一直执行,直到 E 的值为 0。
与此不同,表达式 `E != 0` 是一个比较表达式,其值为真(非 0)或假(0)。当 E 的值不为 0 时,`E != 0` 的值为真;当 E 的值为 0 时,`E != 0` 的值为假。
因此,语句 `while (E != 0);` 与 `while (E);` 是等价的,它们都表示一个死循环,只有当 E 的值为 0 时才会退出循环。但是表达式 E 与 E != 0 并不等价。
相关问题
设E为整型变量,在以下给出的表达式中,与while(E){.}语句中的(E)不等价的表达式是() ●(!E==0)●(E>O||E<0)●(E==0)●(E!=0)
与while(E){.}语句中的(E)不等价的表达式是(E>O||E<0)。
while(E){.}语句中的(E)表示当变量E的值不为0时,执行循环体中的语句。因此,表达式(E!=0)和(E==0)等价于(E)。
而表达式(!E==0)等价于(E==0),因为!E表示E的逻辑反,所以当E为0时,!E为1,!E==0为假,当E不为0时,!E为0,!E==0为真。
表达式(E>O||E<0)表示当E大于O或E小于0时为真,与(E)不等价,因为(E)表示当E不为0时为真。
在循环语句while (e) {……}中,条件表达式e等价于下列表达式中的__
在循环语句 `while (e) {……}` 中,条件表达式 `e` 等价于下列表达式中的 `e`。因为 `while` 循环会一直执行循环体中的语句,直到条件表达式为假时才停止循环。因此,条件表达式 `e` 必须是一个可以求值为真或假的逻辑表达式,只有当 `e` 的值为真时,循环体中的语句才会被执行。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)