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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:54:23+00:00 2026-06-11T00:54:23+00:00

Why aren’t these function prototypes equivalent? void print_matrix(char *name, int SX, int SY, int

  • 0

Why aren’t these function prototypes equivalent?

void print_matrix(char *name, int SX, int SY, int m[SX][SY])

void print_matrix(char *name, int SX, int SY, int **m)
  • 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-11T00:54:25+00:00Added an answer on June 11, 2026 at 12:54 am

    Even though the two function arguments can be consumed in the same way, namely via m[i][j], they’re quite different:

    • int m[M][N] is an array of M arrays of N ints.

    • int **m is a pointer to a pointer to an int.

    You cannot pass arrays as function arguments, so an “array of K elements of type T” decays to a “poin­ter-to-T“, pointing to the first element of the array. Thus it is permissible and equivalent to write the first form as int m[][N] in a function argument, since the value M is lost. However, the value N is not lost; it is part of the type!

    So the following are admissible/erroneous for the first form:

    void f(int arr[M][N]);
    
    int a[M][N];
    int b[2*M][N];
    int c[M][N + 1];
    
    f(a);   // OK
    f(b);   // OK; slowest extent is forgotten in the decay
    //f(c); // Error! 'c' is not an array of {array of N ints}.
    

    For the second form, the meaning is rather different:

    void g(int **p);
    
    int a;
    int * pa = &a;
    
    g(&pa);          // fine, pointer to 'pa'
    
    int arr[M][N];
    
    // g(arr);  // Error, makes no sense
    

    The expression arr designates the pointer to the first element of an array of arrays of N integers, i.e. its type is int (*)[N]. Dereferencing it gives an array of N integers, and not a pointer to an integer.

    There is no way to convert the expression arr into a pointer to a pointer: If you said,

    int ** fool = (int**)arr;
    

    then *fool would point to the first element of the first array (arr[0]), and not to an int pointer. So you cannot dereference the value further, because the value is not a pointer.

    The only correct way to pass a two-dimensional array as a double pointer is to construct an intermediate helper array:

    int * helper[M];   // array of pointers
    
    for (size_t i = 0; i != M; ++i)
    {
        helper[i] = arr[i]; // implicit decay
    }
    
    g(helper);  // or "g(&helper[0])"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Aren't these equivalent? ==SCRIPT A== if (file_exists($file) == false) { return false; } ==SCRIPT
Why aren't these two statements equivalent? defined? foo ? foo << bar : foo
Django objects aren't subscriptable meaning if you have user.name you can't define it with
can anyone tell me why these aren't being calculated correctly. I'm trying to add
Why aren't these the same? php: $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
why aren't the cookies saved when i run the following script: window.onload=init; function init()
Aren't these methods called when the app is about to be shut down? If
Aren't Javascript blocks supposed to execute in the order that they are placed on
Why aren't many commercial, 3D video games (not random open source 2D ones) written
Why aren't my results being filtered by the members from my [Group Hierarchy] returned

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.