|) operator instead of Logical AND(&&) operator [closed]

问题描述 投票:-5回答:1

This is what I code for program which do case conversion of string :

https:

我很困惑,为什么我不能使用逻辑OR(||)运算符,而不是逻辑AND(&&)运算符,在行 if(str[i]>='a'&& str[i]<='z')

c operators
1个回答
0
投票

There are other possible characters after 'z' and below 'a' (ascii table), so it's necessary to do both upper and lower bounds checks with &&. If you used the || operator then the statement could execute if the character were any value, because ALL characters are greater than 'a' or less than 'z'.

© www.soinside.com 2019 - 2024. All rights reserved.