So I got question in my mind! How am I suppose to calculate the Number of elements in an array when I have only its address Suppose I pass an array "A" as an actual parameter to a function and i stored its address in a pointer suppose "*b". Now how will I be able to calculate the length of array A(or number of elements in and array A) with its address(base address) only. Please tell me if I am thinking logically or it. If it is possible please tell me how If not please correct me Why! I can of course calculate length first and the pass both to other functions.
Asked
Active
Viewed 32 times
2
-
4You can't. Period. – tkausl Oct 07 '21 at 01:14
-
2The address does not carry that information. You must convey it separately, or else have some mechanism for recognizing the end from the data themselves. The canonical example of the latter would be C strings. – John Bollinger Oct 07 '21 at 01:17
-
4Since you have C++ tagged, consider abandoning the use of raw arrays and using a library container like [`std::array`](https://en.cppreference.com/w/cpp/container/array) or [`std::vector`](https://en.cppreference.com/w/cpp/container/vector) instead. – user4581301 Oct 07 '21 at 01:24
-
Roger That Sir! – Gol D. Roger Oct 10 '21 at 23:02