Arrays are objects in Java, so the Array type can have a member length that internally stores how long it is. If you want something like that in C++, you could look into std::vector or one of the other standard containers.
Although the correct answer has already been given by Zhuge I would like to point out that you have the option to overload the "[]" operator in C++ and create a Java like object in C++. You just have to be the one to define everything, it isn't done for you.
#include <iostream>
usingnamespace std;
template <typename T, size_t M, size_t N>
void zero_matrix( T (&matrix)[ M ][ N ] )
{
for (size_t m = 0; m < M; m++)
for (size_t n = 0; n < N; n++)
matrix[ m ][ n ] = 0;
}
template <typename T, size_t M, size_t N>
void print_matrix( T (&matrix)[ M ][ N ] )
{
for (size_t m = 0; m < M; m++)
{
for (size_t n = 0; n < N; n++)
cout << matrix[ m ][ n ] << " ";
cout << endl;
}
}
int main()
{
int A[ 3 ][ 4 ];
double B[ 2 ][ 5 ];
zero_matrix( A );
zero_matrix( B );
cout << "A:\n";
print_matrix( A );
cout << "\nB:\n";
print_matrix( B );
return 0;
}