int counter=-1;
NSArray *pointArray=[[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"1",@"2", nil];
NSString *result=[NSString stringWithFormat:@"%d",counter<pointArray.count-1];
Believe it or not the result is 0 !!!
Try and who can tell me why???
Notice that the following code reproduces this issue:
The output of this is
As has been pointed out, the trouble is that you are comparing an
intto anNSUInteger. But recall that, on 64-bit systems,NSUIntegeris atypedefofunsigned long.The behavior we’re seeing is a result of usual arithmetic conversion:
Since neither of the operands are of floating point type, we arrive at
4.. Since the second operand (pointArray.count-1) is of typeNSUInteger, that is of typeunsigned long, the other operand (counter) is converted to typeunsigned long, taking on the value of18446744073709551615which is indeed greater than4.