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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:11:42+00:00 2026-05-17T02:11:42+00:00

I took a hiatus from C and am just getting back into it again.

  • 0

I took a hiatus from C and am just getting back into it again.

If I want to create a 2D array of doubles, I can do it two ways:

double** m_array = (double**) malloc(2*sizeof(double*));
double*  m_array = (double*)  malloc(2*sizeof(double));

OR

double array[2][2];

But, when I wish to pass the malloc’d array versus passing the other, there seems to be two conventions:

//allowed for passing in malloc'd array, but not for other array
func_m(m_array) //allowed
func_m(array) //disallowed
func_m(double** m_array)

//allowed for passing in either array; required for passing in non-malloc'd array
func(m_array) //allowed
func(array) //allowed
func(double array[][2])

In the first, I don’t need any information beyond that it is a pointer to an array of pointers. But it can only be a malloc’d array.

In the second, I need to pass the length of each array that the array of double* points to. This seems silly.

Am I missing something? Thanks in advance.

  • 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-17T02:11:43+00:00Added an answer on May 17, 2026 at 2:11 am

    The first one doesn’t create a 2-D array at all. It creates an array of pointers, which apparently point nowhere. If you did initialize each pointer to be an array, that would still be an array of arrays, not a 2-D array.

    Why don’t you just create a 2-D array?

    double* dynamicArray = malloc(rows * columns * sizeof (double));
    

    or

    double autoArray[rows][columns];
    

    and then you can use either one with this function:

    void func(double* array, size_t rows, size_t columns);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Took about a two week break from development and came back this week to
I took two simple examples from Google Maps v.3 Documentation https://code.google.com/apis/maps/documentation/javascript/examples/maptype-base.html google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/examples/weather_map.html And I
I took this basic upload file script from php.net and it is giving two
I took the plunge this afternoon and began studying LINQ, so far just mucking
I took over a Visual C++ project in Visual Studio 2005 from a colleague.
I took some code from some questions here in SO as well as some
It took me FOREVER to finally find code that can download a doc file
Took me a while to find this bug in my code. Trying to create
I took this from Jon Skeet's C# in depth. He mentioned the following is
I took this script from here : import csv from itertools import izip f

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.