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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:56:36+00:00 2026-06-05T22:56:36+00:00

I try to dynamically allocate one dimension of a two dimensional array. The array

  • 0

I try to dynamically allocate one dimension of a two dimensional array. The array is declared as follows:

uint16_t coord[][2];

I only need to allocate the rows, the number of coordinates.
Over google I found enough code to allocate both of the dimensions, starting from:

uint16_t **coord;

I am not sure if I can still declare the array as above. Do I need to do:

uint16_t *coord[2]; 

or not?

I also need to return the array (the pointer to it) from the allocating function so other functions can access the array like this:

foo = coord[4][0];
bar = coord[4][1];

What’s the correct way to return the allocated array?

  • 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-05T22:56:38+00:00Added an answer on June 5, 2026 at 10:56 pm

    According to the clockwise/spiral rule, the following declaration:

    uint16_t *coord[2];
    

    is an array of two pointers, which seems to be not what you want. However you can use this instead:

    uint16_t (*coord)[2];
    

    You can allocate memory for it like this:

    coord = malloc(num_entries * sizeof(uint16_t[2]));
    

    Now you can access it as a normal multi-dimensional array:

    coord[0][0] = 1;
    coord[0][1] = 2;
    coord[1][0] = 3;
    coord[1][1] = 4;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this simple piece of code to dynamically allocate a 4-dimensional array: #include
I'm using the code above to dynamically allocate an array, do some work inside
I started with https://developers.google.com/maps/articles/phpsqlajax_v3 and am using https://developers.google.com/maps/articles/phpsqlsearch_v3 to try to dynamically filter the
In my program I generate classes dynamically but when I try: String[] args =
I try to dynamically load many scripts in my page function loadAdditionalScripts() { $.when(
I am creating some link buttons dynamically and try to access them in some
I'm try to do some nasty hacky things with dynamically generated code, and I
I dynamically add rows to divStaff using jquery: $(span[id$='lblAddStaff']).click(function() { //$(.staff_tpl).find(input[id$='txtRate']).val(0,00); var staff_row =
I'm try to do a bit of WPF, only really done windows forms until
All- I am using the TreeMap example of D3 to try and dynamically update

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.