Comparison operation on unsigned and signed integers

后端 未结 7 1994
小蘑菇
小蘑菇 2020-11-22 04:17

See this code snippet

int main()
{ 
 unsigned int a = 1000;
 int b = -1;
 if (a>b) printf(\"A is BIG! %d\\n\", a-b);
 else printf(\"a is SMALL! %d\\n\", a         


        
7条回答
  •  后悔当初
    2020-11-22 04:58

    Find a easy way to compare, maybe useful when you can not get rid of unsigned declaration, (for example, [NSArray count]), just force the "unsigned int" to an "int".

    Please correct me if I am wrong.

    if (((int)a)>b) {
        ....
    }
    

提交回复
热议问题