This is what I code for program which do case conversion of string :
我很困惑,为什么我不能使用逻辑OR(||
)运算符,而不是逻辑AND(&&
)运算符,在行 if(str[i]>='a'&& str[i]<='z')
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'
.