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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:29:16+00:00 2026-06-13T23:29:16+00:00

I am a bit of a beginner to OOP so this may be a

  • 0

I am a bit of a beginner to OOP so this may be a silly question!

I would like to use a multidimensional CArray as an instance variable in an objective-c class, and would also like to be able to specify it’s size during runtime, during the objects initialisation method:

@interface ArrayClass : NSObject {

int array[][];

}

-(id)initWithSizeX:(int)sizeX sizeY:(int)sizeY;

@end

This produces the error “Instance variable ‘array’ has unknown size.”

I can only seem to make use of the array if I declare it as having an initial size, say [20][20] for example – But that of course defeats the point because I want it to be decided at runtime!

My guess that is this is necessary as the objects memory footprint needs to be known up front?

Does anybody know if what I am trying to this is possible at all? Are there any workarounds that would allow me to size the array at runtime? Or am I going about this in completely the wrong way?

I know there are a lot of topics about multi-dimensional arrays, but I cannot seem to find anything that answers my question!

  • 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-13T23:29:17+00:00Added an answer on June 13, 2026 at 11:29 pm

    Since you’re working in Objective-C, you might consider using NSArray (or NSMutableArray depending on what you plan on doing with the array). This will let you send it Objective-C messages and get a lot more functionality “for free” due to it being an object, not just a chunk of memory (as an array is in C). Also, if you’re using ARC or garbage collection, it will get memory managed for you.

    But if you know you want to use a C array (which is totally valid), you’ll need to malloc it (and free it when you’re done with it) in your code just like you would normally in C. (You can only get around this when you create a static array of a defined size at compile time, as you noted.)

    EDIT: As @Mahesh pointed out in the comments, you’ll want to declare your array variable as
    int **array;
    instead of
    int[][] array;.

    Take a look here if you need more help with this!

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

Sidebar

Related Questions

A beginner question: I don't know how best to structure this bit of code,
I am a beginner at Objective-C and I am a bit confused at this
Obviously, this question is a bit Rails beginner question, however it is vital for
this is a bit of a beginner's question, but I've searched everywhere and can't
Bit of a beginner question here: Say I have a block of xml: <root>
Bit of a javascript newbie so not sure if this question is easy or
I'm a bit of a beginner with this so i'll try and keep it
Apologies as I'm a bit of a beginner with this. I'm trying to send
I'm a bit new to web development so forgive the slightly beginner question. Can
I am a beginner with Qt, so my question might be a bit basic.

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.