NOT(~) vs NEGATION(!)

前端 未结 4 1453
無奈伤痛
無奈伤痛 2020-12-13 18:58
#include 

using namespace std;
int main(int argc, char *argv[]) 
{
   int i=-5;
   while(~(i))
   {
      cout<         


        
4条回答
  •  感情败类
    2020-12-13 19:56

    '~' is the operator that : ~x = -x-1 and when i = -1, then ~i = 0. if you wonder the value of ~i, you can just print them out:

    #include 
    
    using namespace std;
    int main(int argc, char *argv[]) 
    {
       int i=-5;
       for (int i = -5; i <= 3; i++)
       {
        cout<

    and then you will find: -5 4 -4 3 -3 2 -2 1 -1 0 0 -1 1 -2 2 -3 3 -4

提交回复
热议问题