How do I in C++ find the size of an integer array? For example, if
int a[] = {1,2,3,4,5};
How would I find the length of that array? Is there anything in C++ that I could use on this array that behaves like strlen for strings? Thanks
Printable View
How do I in C++ find the size of an integer array? For example, if
int a[] = {1,2,3,4,5};
How would I find the length of that array? Is there anything in C++ that I could use on this array that behaves like strlen for strings? Thanks
i donno if this works, but something like thisCode:#include <iostream>
using std::cout;
int main()
{
int found=0;
int array[] = {'1', '2', '3', '4', '5'};
for(i=0;found==0;i++)
{
if(array[i]=='')
{
cout << "The array is " << i << " characters big";
found=1;
}
else
{
cout << "Still searching...\n";
}
}
return 0;
}
>How would I find the length of that array?
you don't
>Is there anything in C++ that I could use on this array that behaves like strlen for strings?
no
this is technically impossible since no value is reserved for the end of the array.
define a value to size the array or keep track of it by some other means
#define ARRAY_LENGTH 5
and use ARRAY_LENGTH where ever you need the array size