In the C language, there is the sizeof () keyword . Can be used to calculate the size of an array (the number of bytes in the array), but not the length .
However, it can be divided by the number of bytes of an array of individual elements to calculate the length:
A[7] = {1,2,3,4,5,,6,7};
length = sizeof (a)/sizeof (a[0]);
The above method can be used in C + +, but you can also:
A[7] = {1,2,3,4,5,6,7}
int *abeg = Beg (a);
int *aend = end (a);
Auto dis = Aend-abeg;
cout<<dis<<endl;
In C + +, it is recommended to use vector containers instead of arrays, whose lengths can be calculated directly using Name.size ().
Calculate the size of the array in Java:
public class Testjava {
public static void Main (string[] args) {
int a[] = {1,2,3,4,5};
System.out.println (a.length);
}
}
Calculate the size of the array in Python:
A = [1,2,3,4,5]
Print (Len (a))
Very simple things, but too long did not write code after unexpectedly still forget. It's really going to take more practice.
Array length calculation