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 1023437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:37:11+00:00 2026-05-16T11:37:11+00:00

hi am working with NSArrays using foundation tool and i have wrote the following

  • 0

hi am working with NSArrays using foundation tool and i have wrote the following code

    -(void)simplearrays
{
 NSMutableArray *arr = [NSMutableArray arrayWithCapacity:3];

 for(int i =0;i<3;i++)
 {
  scanf("%d",&arr[i]);
 }
 for(int j =0; j<3;j++)
 {
  printf("\n%d",arr[j]);
 }
}

My query is that the above code when executed shows the given output but the i get an error once the application finishes execution which says that “can’t allocate region” can you please help.

Also i wanted to know the difference between NSArray and NSMutable Array in icode blog i have read that nsarray can dynamically resize so if NSArray can dynamically resize then why to use NSMutable array or a better one would be when to use NSArray and when to use NSMutable Array???

  • 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-05-16T11:37:11+00:00Added an answer on May 16, 2026 at 11:37 am

    Cocoa arrays are not C arrays. They are container objects with some similarities to Java vectors and array lists.

    You cannot add objects or retrieve them using the C subscript syntax, you need to send messages to the object.

    -(void)simplearrays
    {
        NSMutableArray *arr = [NSMutableArray array]; 
        // arrayWithCapacity: just gives a hint as to how big the array might become.  It always starts out as
        // size 0.
    
        for(int i =0;i<3;i++)
        {
            int input;
            scanf("%d",&input);
            [array addObject: [NSNumber numberWithInt: input]];
            // You can't add primitive C types to an NSMutableArray.  You need to box them
            // with an Objective-C object
        }
        for(int j =0; j<3;j++)
        {
           printf("\n%d", [[arr objectAtIndex: j] intValue]);
           // Similarly you need to unbox C types when you retrieve them
        }
        // An alternative to the above loop is to use fast enumeration.  This will be
        // faster because you effectively 'batch up' the accesses to the elements
        for (NSNumber* aNumber in arr)
        {
           printf("\n%d", [aNumber intValue]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

working on an app and using the following code: - (void)viewDidLoad { [super viewDidLoad];
I am using the following code snippet for an app I'm working on to
I have a little bit of deserialisation using JSONKit. It is working, but what
I have been working using openFrameworks, on a problem that is posted on the
I have this code working when I build for debug on my phone and
In my MainViewController I am using this code: static NSBundle *bundle = nil; +(void)setLanguage:(NSString
Working on a website that has Employee and Branch entities, using a database table
Working on a new app and using restful-authentication. I was trying to make it
I am working on a mail application. I have a table view in a
I have checked using instruments and not found any memory leaks. when i check

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.