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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:28:08+00:00 2026-06-13T04:28:08+00:00

Possible Duplicate: passing 2D array to function My question is related to passing an

  • 0

Possible Duplicate:
passing 2D array to function

My question is related to passing an array as a C++ function argument. Let me show the example first:

void fun(double (*projective)[3])
{
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
        {
            projective[i][j]= i*100+j;
        }
}

int main()
{
    double projective[3][3];     

    fun(projective);
    for(int i=0; i<3; i++)
    {
        cout<<endl;
        for(int j=0; j<3; j++)
            cout<<projective[i][j]<<"   ";
    }


    return 0;
}

In the example, the passing argument for fun is an array, and I was wondering whether there are other ways of passing this argument. Thanks!

  • 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-13T04:28:10+00:00Added an answer on June 13, 2026 at 4:28 am

    fun takes a pointer-to-array-of-3-double and it assumes (relying on the caller) that this points to the first element of an array of at least 3 arrays-of-3-doubles. Which it does, because as you say the argument supplied to the call in main is an array. This immediately decays to a pointer to its first element.

    One alternative would be for fun to take a pointer-to-3×3-array-of-double, since it assumes that size anyway and the caller does in fact have such a beast:

    void fun(double (*p_projective)[3][3])
    {
        for(int i=0; i<3; i++)
            for(int j=0; j<3; j++)
            {
                (*p_projective)[i][j]= i*100+j;
            }
    }
    

    Call it with fun(&projective).

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

Sidebar

Related Questions

Possible Duplicate: jQuery question: what does it really mean? For example, (function (exports, $,
Possible Duplicate: Passing an array as an argument in C++ Sizeof an array in
Possible Duplicate: Difference between passing array and array pointer into function in C I
Possible Duplicate: C++ passing variables in from one Function to the Next. The Program
Possible Duplicate: passing an empty array as default value of optional parameter in c#
Possible Duplicate: Is Java pass by reference? I have a question about passing by
Possible Duplicate: MySQL query using an array Passing an array to mysql I have
Possible Duplicate: passing a pointer by reference in c++ I have a function that
Possible Duplicate: Passing a class (“Country.class”) as an argument in Java I am trying
Possible Duplicate: Passing multidimensional arrays as function arguments in C I'm trying 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.