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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:05:38+00:00 2026-05-26T12:05:38+00:00

In Objective-C, I declare a C array like this: int length = 10; int

  • 0

In Objective-C, I declare a C array like this:

int length = 10;
int a[length];

This does not cause any errors in Xcode but other compliers like Visual Studio.
Please tell me how it works. Should I use it or use malloc/calloc instead?

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

    Variable length arrays were introduced in C99. Microsoft’s current compiler (VC2010) doesn’t support C99 (or at least the VLA part of it) as far as I’m aware.

    You can use malloc to do the same sort of thing, you just have to remember to free it when you’re done.

    Something like:

    int length = 10;
    int *a = malloc (length * sizeof(int));
    if (a == NULL) {
        doSomethingIntelligentSinceNoMemoryLeft();
    } else {
        useToHeartsContent (a[0], "thru", a[9]);
        free (a);
    }
    

    You can probably also use alloca which is similar to VLAs in that it allocates space on the stack for variables memory blocks.

    But you have to be careful. While alloca gives you automatic de-allocation on function exit, the stack is usually a smaller resource than the malloc heap and, if you exhaust the heap, it gives you back NULL. If you blow out your stack, that will probably manifest itself as a crash.

    alloca(n) is probably acceptable for small enough values of n.

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

Sidebar

Related Questions

is it possible to declare a variable length array with global scope in objective-c?
In my objective c class, I'd like to sort an array like this: NSArray
I understand that in Objective-C you declare an array in the header file and
I would like to declare a pointer to a pointer in objective-c. I have
How to declare and use global variable with extern in Objective C and other
I can declare NSMutableArray or NSArray but I want to declare class array. Let
How to declare the virtual functions in Objective C. virtual void A(int s); How
Possible Duplicate: Objective C multiple inheritance Hi, Objective C does not support multiple inheritance.
I have an objective-c/xcode project with several header and implementation files. I'd like to
How do you declare, set properties, synthesize, and implement an int array of size

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.