An unsigned int value that does not produce the correct result

the following program should print “error,” but printing it successfully .why?

#include<iostream>
using namespace std;
int main()
{ 
   unsigned int a;
   a=-10;

   if(a == -10)
        cout << "success" ;
   else
        cout << "error" ;

   return 0;
}
+3
source share
1 answer

The conversion for comparison makes them equal again. But this should make the compiler issue a warning.

+6
source

Source: https://habr.com/ru/post/1778047/


All Articles