与标准的if-else语句相比,?:运算符有什么好处和缺点.显而易见的是:
有条件的?:运营商
标准If/Else
根据声明,可读性似乎各不相同.在第一次接触到?:运算符后的一段时间内,我花了一些时间来精确地消化它是如何工作的.您是否会建议尽可能使用它,或者坚持if/else,因为我与许多非程序员一起工作?
我可以请一些帮助理解一下,如果是速记吗?我评论了我的想法.
//Bitwise AND not sure how it decides 32 or 0, then set board[i]
board[i] = (randNum & 1024) ? 32 : 0;
//it the j variable j in the neighborOffset array, then mods it by 2048
//then takes that variable from the board array, then shifts 1 to 32
//then bitwise and of those 2 variables.
if(board[(i + neighborOffset[j]) % 2048] & (1 << 5))
//Not sure about this one. Can someone please explain it?
board[i] |= ((board[i] ^ …Run Code Online (Sandbox Code Playgroud)