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

  • SEARCH
  • Home
  • 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 1114963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:05:05+00:00 2026-05-17T03:05:05+00:00

I have a C array defined in my method as: int c = 4;

  • 0

I have a C array defined in my method as:

int c = 4;
int r = 5;
keysArray[c][r];

I have this for loop, which works, populating the keysArray as expected.

for (int row = 0; row < r; row++) {
    for (int column = 0; column < c; column++){
        keysArray[column][row] = [anotherArray objectAtIndex:0];
        NSLog(@"array1 %@",keysArray[column][row]);
        [anotherArray removeObjectAtIndex:0];
    }
}

Then in a for loop underneath, featuring exactly the same looping counter structure, when i try to NSLog the array, it gives an EXC_BAD_ACCESS.

for (int row = 0; row < r; row++){
    for (int column = 0; column < c; column++) {            
        NSLog(@"array2: %@",keysArray[column][row]); //EXC_BAD_ACCESS here
    }
}

What would cause this to happen, given that the keysArray is defined in the method body, outside of both sets of loops?

  • 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-17T03:05:05+00:00Added an answer on May 17, 2026 at 3:05 am

    You need to retain the objects held in your C array. Unlikes an NS*Array, a C array does not retain on adding to the array.

    However, for a no-holes 2D array like that, I’d just use a single NSMutableArray. Any N-dimensional array can be represented as a line– as a one dimensional array– with simple math.

    Namely, to determine the index of an object at (X,Y), use (Y * width) + X).

    The only caveat is that NS*Array does not support “holes”. You will need to fill the array row by row. That is, for a 3×4 (3 wide, 4 tall) array, you would fill it in the order 0,0, 1,0, 2,0, 0,1, 1,1, etc…

    Obviously, insert and remove operations will mess up your 2D representation (but they would in an NSMutableArray of NSMutableArrays, too).

    Alternatively, use NSPointerArray as it can have holes.

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

Sidebar

Related Questions

I have an array declared inside a user defined method. I use this array
Possible Duplicate: Remove element of a regular array I have a method defined which
I have a program, which takes a parameter from the args[] array, defined in
I defined this simple method: public static boolean isBorder(int x, int y) throws CollisionDetectionException
I have the following method defined: internal string GetInformation(string recordInformation) { int bufferSize =
I have these methods. I have defined a char array in stringcontent.h file and
An array is defined of assumed elements like I have array like String[] strArray
I have an array defined as; static double Temp_data[TABLE_SIZE]; I want to change the
I have a Java array defined already e.g. float[] values = new float[3]; I
I have defined an array like so : var myArray = {myNewArray: ['string1' ,

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.