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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:43:49+00:00 2026-06-08T22:43:49+00:00

int array[5][3]; (obviously) creates a multi-dimensional C array of 5 by 3. However, int

  • 0
int array[5][3];

(obviously) creates a multi-dimensional C array of 5 by 3. However,

int x = 5;
int array[x][3];

does not. I’ve always thought it would. What don’t I understand about C arrays? If they only allow a constant to define the length of a C array, is there a way to get around this in some way?

  • 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-08T22:43:51+00:00Added an answer on June 8, 2026 at 10:43 pm

    In ANSI C (aka C89), all array dimensions must be compile-time integer constants (this excludes variables declared as const). The one exception is that the first array dimension can be written as an empty set of brackets in certain contexts, such as function parameters, extern declarations, and initializations. For example:

    // The first parameter is a pointer to an array of char with 5 columns and an
    // unknown number of rows.  It's equivalent to 'char (*array_param)[5]', i.e.
    // "pointer to array 5 of char" (this only applies to function parameters).
    void some_function(char array_param[][5])
    {
        array_param[2][3] = 'c';  // Accesses the (2*5 + 3)rd element
    }
    
    // Declare a global 2D array with 5 columns and an unknown number of rows
    extern char global_array[][5];
    
    // Declare a 3x2 array.  The first dimension is determined by the number of
    // initializer elements
    int my_array[][2] = {{1, 2}, {3, 4}, {5, 6}};
    

    C99 added a new feature called variable-length arrays (VLAs), where the first dimension is allowed to be a non-constant, but only for arrays declared on the stack (i.e. those with automatic storage). Global arrays (i.e. those with static storage) cannot be VLAs. For example:

    void some_function(int x)
    {
        // Declare VLA on the stack with x rows and 5 columns.  If the allocation
        // fails because there's not enough stack space, the behavior is undefined.
        // You'll probably crash with a segmentation fault/access violation, but
        // when and where could be unpredictable.
        int my_vla[x][5];
    }
    

    Note that the latest edition of the C standard, C11, makes VLAs optional. Objective-C is based off of C99 and supports VLAs. C++ does not have VLAs, although many C/C++ compilers such as g++ which support VLAs in their C implementation also support VLAs in C++ as an extension.

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

Sidebar

Related Questions

Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to
int array[] = {-1, 4, -2, 5, -5, 2, -20, 6}; If I had
i have two int array of images , i have implemented it in grid
I am using an int array to hold a long list of integers. For
To initialize an int array with all zeros, do I need to use: int
I have an int array containing gray scale values from 0-254, i also have
I have an int array which has no elements and I'm trying to check
Assume that int array arrayName is a member of class className, How can I
I have an int array for which i have allocated space for 100 elements.
Can I declare an int array, then initialize it with chars? I'm trying to

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.