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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:45:46+00:00 2026-05-26T14:45:46+00:00

Okay so you have and array A[]… that is passed to you in some

  • 0

Okay so you have and array A[]… that is passed to you in some function say with the following function prototype:

void foo(int A[]);

Okay, as you know it’s kind of hard to find the size of that array without knowing some sort of ending variable or knowing the size already…

Well here is the deal though. I have seem some people figure it out on a challenge problem, and I don’t understand how they did it. I wasn’t able to see their source code of course, that is why I am here asking.

Does anyone know how it would even be remotely possible to find the size of that array?? Maybe something like what the free() function does in C??

What do you think of this??

template<typename E, int size>
int ArrLength(E(&)[size]){return size;}

void main()
{
    int arr[17];
    int sizeofArray = ArrLength(arr);
}
  • 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-26T14:45:47+00:00Added an answer on May 26, 2026 at 2:45 pm

    The signature of that function is not that of a function taking an array, but rather a pointer to int. You cannot obtain the size of the array within the function, and will have to pass it as an extra argument to the function.

    If you are allowed to change the signature of the function there are different alternatives:

    C/C++ (simple):

    void f( int *data, int size );             // function
    f( array, sizeof array/sizeof array[0] );  // caller code
    

    C++:

    template <int N>
    void f( int (&array)[N] );                 // Inside f, size N embedded in type
    f( array );                                // caller code
    

    C++ (though a dispatch):

    template <int N>
    void f( int (&array)[N] ) {                // Dispatcher
       f( array, N );
    }
    void f( int *array, int size );            // Actual function, as per option 1
    f( array );                                // Compiler processes the type as per 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a tableview class that lists 100 Foo objects. It has: @property
Okay, I have an array that is used to transport names, it looks like
Okay so I have an array of 9 integers. Some of values are given
I have the following arrays in PHP (okay they are a bit bigger but
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay so I have the following Code which appends a string to another in
Okay, I have the following PHP code to extract an email address of the
Okay I have been racking my brain trying to build a JSON array from
Okay, so, I'm doing a simple lookup. I have an array of NSString objects
Okay, I need some solid OOP advice. Here's the setup: I have a player

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.