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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:26:44+00:00 2026-05-24T06:26:44+00:00

I have two questions regarding this code. What does the double*** pdata and int***

  • 0

I have two questions regarding this code.

  1. What does the double*** pdata and int*** pmask mean? A pointer to a pointer to a pointer?
    Why or when is this necessary?

  2. int and double are different types, but are double* and int* also different. Can we operate on them without a cast?

Here’s the code I’m puzzled about:

static int makedatamask(int nrows, int ncols, double*** pdata, int*** pmask)
    { int i;
      double** data;
      int** mask;
      data = malloc(nrows*sizeof(double*));
      if(!data) return 0;
      mask = malloc(nrows*sizeof(int*));
      if(!mask)
      { free(data);
        return 0;
      }
      for (i = 0; i < nrows; i++)
      { data[i] = malloc(ncols*sizeof(double));
        if(!data[i]) break;
        mask[i] = malloc(ncols*sizeof(int));
        if(!mask[i])
        { free(data[i]);
          break;
        }
      }
      if (i==nrows) /* break not encountered */
      { *pdata = data;
        *pmask = mask;
        return 1;
      }
      *pdata = NULL;
      *pmask = NULL;
      nrows = i;
      for (i = 0; i < nrows; i++)
      { free(data[i]);
        free(mask[i]);
      }
      free(data);
      free(mask);
      return 0;
    }
  • 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-24T06:26:44+00:00Added an answer on May 24, 2026 at 6:26 am

    Yes – the types are triple pointers or pointers to pointers to pointers. Occasionally they are necessary, but be very scared. In this case, you are allocating two similarly sized 2D arrays, and you have to return the two values by reference, so the triple pointers are necessary, at least while you keep the current function design.

    Yes – a double * and an int * are different types; they point to different types. You can do appropriate operations on them without a cast. However, if you are thinking that you can combine the two parallel operations into one, you are probably mistaken.

    Your error recovery might be simpler if you created some sub-functions:

    static int **alloc_2d_int_array(int nrows, int ncols)
    {
        ...
    }
    
    static double **alloc_2d_double_array(int nrows, in ncols)
    {
        ...
    }
    

    Your main allocation function would then simply call these two sequentially. If the second failed, the main allocation function would call the cleanup for the first allocated array. The cleanup code probably needs the relevant size, so you’d probably have:

    static void free_2d_double_array(int nrows, double **array)
    {
        ...
    }
    
    static void free_2d_int_array(int nrows, int **array)
    {
        ...
    }
    

    These functions might even be visible outside the source (not static).

    You might also consider using a structure to describe the arrays (rows and columns), and the pointers to the arrays. This would allow you to avoid the explicit triple-pointer notation too.

    struct double_array
    {
        int      nrows;
        int      ncols;
        double **array;
    };
    

    Etc.

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

Sidebar

Related Questions

I actually have two questions regarding the same problem but I think it is
I have two questions regarding client-side validation in ASP, relating to the following setup:
I have a question regarding GetTickCount function, I have two calls to this function
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have two questions: 1) How can I make an array which points to
I have two questions. Do realloc() and memcpy() copy the entries in an array
I have two tables (well, two relevant for this question) : Bets (holds the
Actually, this question seems to have two parts: How to implement pattern matching? How
This might be a bit of a silly question but; If I have two
I have a couple of conceptual questions: regarding serving static files (media) in Django

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.