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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:57:36+00:00 2026-05-27T10:57:36+00:00

Is it a right way to pass a pointer to dynamic array? Is it

  • 0

Is it a right way to pass a pointer to dynamic array? Is it going to work? If not, explain why, if it does, explain why as well. Thank you.

struct record
{
    char * community_name;
    double data[10];
    double crimes_per_pop;
};

void allocate_struct_array(struct record *** r);

int main()
{
    /* allocating pointer to an array of pointers */
    struct record ** r;

    /* passing its address to a function */
    allocate_struct_array( &(**r) );
}

/* function gets an address */
void allocate_struct_array(struct record *** r)
{
   ...
}

What I was trying to do is to allocate an array of pointers, where each pointer points to structure record. Function suppose to allocate this array using just pointer to r, which was declared in main. Was playing with this code, but cannot make it to work.

  • 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-27T10:57:36+00:00Added an answer on May 27, 2026 at 10:57 am

    In the function interface, you only need a double pointer struct record **r and not a triple pointer.

    An array can be represented by a struct record *array; so a pointer to that is struct record **ptr_to_array.

    You call the function with &array.

    struct record
    {
        char * community_name;
        double data[10];
        double crimes_per_pop;
    };
    
    void allocate_struct_array(struct record **r);
    
    int main()
    {
        struct record *r;
        allocate_struct_array(&r);
    }
    
    
    void allocate_struct_array(struct record **r)
    {
        *r = malloc(23 * sizeof(struct record));
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it's probably not the right way to structure a database but does
So, right now, I just pass a pointer to a Queue object (implementation doesn't
This might be the wrong way of doing things, but I pass an array
What is the right way to populate the model for the index page in
What is the right way to perform some static finallization? There is no static
What's the right way to go about saving data like Pages, Numbers and other
What is the right way to create custom pgsql types for django application so
Is this the right way to do a nested navigation? <dl> <dt>Struktur</dt> <dd> <ul
What's the right way to control timeouts, from the client, when running against a
What's the right way in Drupal to create reports? I was hoping to use

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.