Logical equality in C

前端 未结 4 648
暗喜
暗喜 2021-01-17 20:07

[It seems odd this doesn\'t exist, so apologies in advance if it\'s a duplicate]

I want to test for logical equality in C. In other words, I want to know whether tw

4条回答
  •  梦谈多话
    2021-01-17 20:39

    You typically see this:

    if ((a == 0) == (b == 0))
    

    Or

    if (!!a == !!b)
    

    Since !!a evaluates to 1 if a is nonzero and 0 otherwise.

    Hope this helps!

提交回复
热议问题