How in C++ get array length with pointers only ? I know that tab name is pointer to first element, but what next ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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:
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:And just for the size:
I use these utility functions from time to time.