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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:05:54+00:00 2026-05-30T14:05:54+00:00

How do i create a three dimensional array where only one of the dimensions

  • 0

How do i create a three dimensional array where only one of the dimensions is known at compile time.
The content of the array is struct values as

struct mat
{
char x[3];
int a;
}

struct samp
 {
   int a;
   struct mat;
 }

The array is supposed to store ‘samp’ and its size is as

   struct samp samp_arr[unknown][10][unknown];

the first time the program runs the first dimension of samp_arr will be one and the last dimension will grow with the number of samp structures put into the array. After a while the first dimension should be incremented by one and any undefined number of samp structs will be put into it. And so on

  • 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-30T14:05:55+00:00Added an answer on May 30, 2026 at 2:05 pm

    If you have a C99 complying compiler you don’t have to re-invent the wheel, multi-dimensional arrays even with dynamic bounds are part of the language.

    struct samp samp_arr[unknown][10][unknown];
    

    (supposing that unknown is an expression that evaluates to the value of your liking.)

    Usually it is a bad idea, though, to allocate such a large variable on the stack, so you should use malloc and friends to allocate it:

    struct samp (*samp_arr)[10][unknown] = malloc(sizeof(struct samp[unknown][10][unknown]));
    ...
    // use it
    samp_arr[i][j][k].a = ...
    ...
    free(samp_arr);
    

    This declares a pointer to a two-dimensional array.

    Wenn passing your array to functions you can do similar, you’d just have to watch that the array bounds come first in the argument list, such that they are known when it comes to the array itself:

    int fun(size_t r, size_t s, size_t t, struct samp (*A)[s][t]) {
     ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array like this (one dimension only): $arr = array('one', 'two', 'three',
I have a created 4 dimensional array in JavaScript. One column contains String values
I want to create two and three dimensional vectors using a constructor in a
In this example I create three buttons 'one' 'two' 'three'. When clicked I want
I want to create a combobox in flex which will take three values, Available,
I am attempting a basic recursion to create multi-dimensional arrays based on the values
I'm trying to create a 2 dimensional array that is fairly large and I
Is there a standard method to create a new array from a two dimensional
I need to create a mutable two-dimensional array in Objective-C. For example I have:
I would like to create something like a pointer to a 2 dimensional array

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.