+ 3
How does an array figures out the length.
How does an array figures out the length. Or is it because it count a letter one by one of a string (word)?
5 Answers
+ 8
Nikhil Sharma Thanks for informing međ
+ 7
Example
int[] arr={1,2,3,4,5};
arr.length() is 5 because arr has 5 elements
+ 3
Thanks muhd khairul
+ 2
Muhd Khairul Amirin Bin Yaacob Array doesn't have length () method. We can figure out it's size by length instance variable.
--> arr.length
length () is available in String class to know the size of the string.
+ 1
In C
#include <stdio.h>
int len(char s){
int c ,i;
c=i=0;
c=s[i]
while ( c != '\0'){
i++;
c=s [i]
}
return i;
}
int main (){
//creating character array
char str [90];//Assume Hello World is the string
int i = len (str);//length =10
}