Suri
Suri

Reputation: 3357

unsigned int value not giving correct result

following program should print "error" but its printing success.why?

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

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

   return 0;
}

Upvotes: 3

Views: 175

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799230

The conversion for comparison makes them equal again. But it should cause the compiler to emit a warning.

Upvotes: 6

Related Questions