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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:59:04+00:00 2026-05-14T03:59:04+00:00

Ref. to my last post and sellibitze’s comment to that post on passing array

  • 0

Ref. to my last post and sellibitze’s comment to that post on passing array by ref rather than by value, why is it that when I’m passing array by value compiler can deduce arguments but it won’t do it if I pass it by value?

template<class T,int row, int col>
void invert(T (&a)[row][col]) //NOTE AMPERSAND

in main with declaration above I can call:

int main(int argc, char* argv[])
{
invert(a);//HERE ARGUMETS ARE AUTOMATICALLY DEDUCED
}

but without ampersand I would have to call it like so:

 int main(int argc, char* argv[])
    {
    invert<int,3,4>(a);
    }

@Paul So just to make it clear when I’m declaring fnc:

void f(int a[]);//I'm passing a pointer

but when I’m declaring:

void f(int &a[]);//I'm passing a ref?

Do I understand this correctly now?

  • 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-14T03:59:04+00:00Added an answer on May 14, 2026 at 3:59 am

    That’s because when you pass an array “by value” it decays to a pointer. That is, you are in fact passing a pointer to the first element without any size information.

    When you have a signature like this:

     void foo(int arr[10]);
    

    then the value 10 is completely ignored and you can pass arrays of ints of any size to it. It is exactly the same as

     void foo(int arr[]);
    

    or

    void foo(int* arr);
    

    As you can see the size information is not preserved, and therefore it cannot be used to deduce the size of the array.

    With a two-dimensional array, the first dimension decays. For example: an array of 10 arrays of 20 integers (int arr[10][20]) decays to a pointer to arrays of 20 integers (int (*arr)[20]) etc, so the value 10 cannot be deduced but the size of the second dimension (20) is preserved an can be deduced.

    template<class T,int row, int col>
    void foo(T (&a)[row][col]) { }
    
    template <class T, int col>
    void bar(T arr[][col]) {}
    
    int main()
    {
        int a[10][20];
        foo(a);
        bar(a);
    }
    

    When you pass something by reference, the type is preserved, the arrays don’t decay and all the size information will remain available.

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

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As Java developer I can't say much about C#, but… May 16, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer Basically you have two options scale_x_continuous(limits = c(-5000, 5000)) or… May 16, 2026 at 2:32 pm
  • Editorial Team
    Editorial Team added an answer I would suggest employing a WebView for this. You can… May 16, 2026 at 2:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Ref: Forms, Post and submit buttons Following on from my last question, I've attempted
Pretty straight forward. MSDN states that you can use ref, but not out for
I want to know how I can optimize it, preferably without changes in tables
I'm reading Joe Duffy's post about Volatile reads and writes, and timeliness , and
The more I see ref used in production code, the more misuse I encounter
how to convert from ITM ref (Israel new map) to GPS ref and from
Is there a way to generate a unique ref for a user? Maybe based
Let's assume that I have a complex hash reference $hash_ref , and I would
Say I have a simple query like this: SELECT * FROM topics ORDER BY
I have the below method for spellchecking in my in house app. As a

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.