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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:38:44+00:00 2026-05-13T23:38:44+00:00

How in C++ get array length with pointers only ? I know that tab

  • 0

How in C++ get array length with pointers only ? I know that tab name is pointer to first element, but what next ?

  • 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-13T23:38:44+00:00Added an answer on May 13, 2026 at 11:38 pm

    You cannot. A pointer is just a memory location, and contains nothing special that could determine the size.

    Since this is C++, what you can do is pass the array by reference like so:

    template <typename T, size_t N>
    void handle_array(T (&pX)[N])
    {
        // the size is N
    
        pX[0] = /* blah */;
        // ...
        pX[N - 1] = /* blah */;
    }
    
    // for a specific type:
    template <size_t N>
    void handle_array(int (const &pX)[N]) // const this time, for fun
    {
        // the size is N
    
        int i = pX[0]; // etc
    }
    

    But otherwise you need to pass start & end and do a subtraction, like Alok suggests, a start & size, like you suggest, or ditch a static array and use a vector, like Tyler suggests.

    If you know the size of the array you’ll be working with, you can make a typedef:

    typedef int int_array[10];
    
    void handle_ten_ints(int_array& pX)
    {
        // size must be 10
    }
    

    And just for the size:

    template <typename T, size_t N>
    size_t countof(T (&pX)[N])
    {
        return N;
    }
    
    template <typename T, size_t N>
    T* endof(T (&pX)[N])
    {
        return &pX[0] + N;
    }
    
    // use
    int someArray[] = {1, 2, 6, 2, 8, 1, 3, 3, 7};
    
    size_t count = countof(someArray); // 9
    std::for_each(someArray, endof(someArray), /* ... */);
    

    I use these utility functions from time to time.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've got it. As stated in the update to my… May 16, 2026 at 12:40 pm
  • Editorial Team
    Editorial Team added an answer I have listed out the "main topics" listed on the… May 16, 2026 at 12:40 pm
  • Editorial Team
    Editorial Team added an answer This JavaScript: document.getElementById("associate").focus(); will put the cursor in your input… May 16, 2026 at 12:40 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

It's a pointer to an array of LSA_UNICODE_STRING structures. I found some code that
I know this question has been done but I have a slightly different twist
I got the following problem: I have an array of char pointers char *opts[]
Sounds simple enough, but its not working. In this example, I want to set
Hey, I am trying to convert NSString to a C string using cStringUsingEncoding but
I have an array, $scans. I want to query MySQL with all the values
//get var of posted info so user does not //have to reinsert if if
here is my xml: <record> <id>12342</id> <name>xx</name> <blah1>asdfas</blah1> <blah2>asdfas</blah2> ..... </record> I would like
I was wondering, in java, is it possible to in anyway, simulate pass by
These types come from the demos for FastCGI Dll Library (with SIGTERM handler) for

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.