Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:05:20+00:00 2026-06-17T11:05:20+00:00

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

  • 0
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???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:05:21+00:00Added an answer on June 17, 2026 at 11:05 am

    Notice that the following code reproduces this issue:

    #include <Foundation/Foundation.h>
    int main(int argc, char *argv[]) {
        NSUInteger uns = 4;
        int sig = -1;
        BOOL cmp = (sig < uns);
        NSLog(@"(%d<%zu)=%d", sig, uns, cmp);
    }
    

    The output of this is

     (-1<4)=0
    

    As has been pointed out, the trouble is that you are comparing an int to an NSUInteger. But recall that, on 64-bit systems, NSUInteger is a typedef of unsigned long.

    The behavior we’re seeing is a result of usual arithmetic conversion:

    1. If either operand is of type long double, the other operand is converted to type long double.
    2. If the above condition is not met and either operand is of type double, the other operand is converted to type double.
    3. If the above two conditions are not met and either operand is of type float, the other operand is converted to type float.
    4. If the above three conditions are not met (none of the operands are of floating types), then integral conversions are performed on the operands as follows:
      • If either operand is of type unsigned long, the other operand is converted to type unsigned long.
      • If the above condition is not met and either operand is of type long and the other of type unsigned int, both operands are converted to type unsigned long.
      • If the above two conditions are not met, and either operand is of type long, the other operand is converted to type long.
      • If the above three conditions are not met, and either operand is of type unsigned int, the other operand is converted to type unsigned int.
      • If none of the above conditions are met, both operands are converted to type int.

    Since neither of the operands are of floating point type, we arrive at 4.. Since the second operand (pointArray.count-1) is of type NSUInteger, that is of type unsigned long, the other operand (counter) is converted to type unsigned long, taking on the value of 18446744073709551615 which is indeed greater than 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static class clsCounter { static int count; public static int Counter { get
I have an NSArray with 5 objects. NSArray *tmpArry2 = [[NSArray alloc] initWithObjects:@test1, @test2,
for example: void decrement(int counter) { counter--; } int counter = 20; for (int
public class SelfCallingTest { private static int counter; public void SelfCallingMethod(int counter) { Console.WriteLine(The
I've got a private int counter inside my class and I initialized it as
Today I came across this question: you have a code static int counter =
Given the following code : for (int i=0; i<n; i++) { counter += myArray[i];
Code: static int counter = 0; int add(int x) { counter++; return ++x; }
In the User Control code im doing in the top: int counter; In constructor:
Here is my code: #include <gtk/gtk.h> static int counter = 0; static PangoLayout* layout;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.