Can I use the not operator in C++ on int values?

后端 未结 5 893
有刺的猬
有刺的猬 2021-01-04 03:16

Strange question, but someone showed me this, I was wondering can you use the not ! operator for int in C++? (its strange to me).

#include 
u         


        
5条回答
  •  抹茶落季
    2021-01-04 03:44

    The build-in ! operator converts its argument to bool. The standard specifies that there exists a conversion from any arithmetic type(int, char,.... float, double...) to bool. If the source value is 0 the result is true, otherwise it is false

提交回复
热议问题