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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:30:09+00:00 2026-05-12T12:30:09+00:00

I have the following code which works fine… int testarr[3][3] = { {1,1,1}, {1,0,1},

  • 0

I have the following code which works fine…

int testarr[3][3] = {
  {1,1,1},
  {1,0,1},
  {1,1,1}
};   
[self testCall: testarr];

Which calls this function:

- (void)testCall: (int[3][3]) arr {

    NSLog(@"cell value is %u",arr[1][1]);
}

I need the array to be of variable length – What is the best way to declare the function?

Using blanks doesn’t work:

- (void)testCall: (int[][]) arr { 

Thanks for your help.

  • 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-12T12:30:09+00:00Added an answer on May 12, 2026 at 12:30 pm

    I would write this as:

    - (void) testCall: (int *) aMatrice;
    

    Doing so allows you to avoid multiple mallocs and the math to calculate a single offset in a linear array based on x, y coordinates in a 2D array is trivial. It also avoids the multiple mallocs implied by int** and the limitations of 2D array syntax perpetuated by the language.

    So, if you wanted a 4×5 array, you might do:

    #define WIDTH 4
    #define HEIGHT 5
    #define INDEXOF(x,y) ((y*WIDTH) + x)
    
    int *myArray = malloc(sizeof(int) * 5 * ELEMS_PER_ROW);
    

    You could then initialize the array linearly or with a nested for loop:

    for(int x=0; x<width; x++)
        for(int y=0; y<height; y++)
            myArray[INDEXOF(x,y)] = ... some value ...;
    

    And you would pass it to the method like:

    [foo testCall: myArray];
    

    Though you might want to also carry along the width and the height or, better yet, create a IntMatrix subclass of NSObject that wraps all of the pointer arithmetic and storage beyond a nice clean API.

    (all code typed into SO)

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

Sidebar

Ask A Question

Stats

  • Questions 220k
  • Answers 220k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ^(?!mpeg).* This uses a negative lookahead to only match a… May 13, 2026 at 12:00 am
  • Editorial Team
    Editorial Team added an answer This is probably the best your going to get without… May 13, 2026 at 12:00 am
  • Editorial Team
    Editorial Team added an answer This is exactly what connect(2) and getsockname(2) are for. As… May 13, 2026 at 12:00 am

Related Questions

I have the following code which works fine. However, I only want to return
I have the following code which works fine... int testarr[3][3] = { {1,1,1}, {1,0,1},
I have the following code which works just fine when the method is POST,
I have the following jquery code which works fine. $('#onlyTwo').click(function() { $(#textarea3).attr(disabled, true); $(#textarea4).attr(disabled,
So following on from this question: Erlang lists:index_of function? I have the following code

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.