int array1[] = {1, 2, 3, 4, 5};
int array2[] = {6, 7, 8, 9};
int *arrays[] = {array1, array2};
How to get length of the array1 and array2 from arrays
? (arrays[0]
length and arrays[1]
length)
int array1[] = {1, 2, 3, 4, 5};
int array2[] = {6, 7, 8, 9};
int *arrays[] = {array1, array2};
How to get length of the array1 and array2 from arrays
? (arrays[0]
length and arrays[1]
length)
Not.
Pointers to datatype (int
e.g.), which arrays decay to in this context, do not know about the size. It is similar to the problem that you cannot find the size within a function.
This means you need to know it, e.g. because you have in a second array the size information, or like in the case of 0-terminated characters sequences, a way to dermine the length from the content.
In order to be helpful, I join those (e.g. in the comments here), to use a C++ container class, most prominently the std::vector
.