+ 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)?

10th Jun 2018, 8:05 AM
Trevor Netshisaulu
Trevor Netshisaulu - avatar
5 Answers
+ 8
Nikhil Sharma Thanks for informing me😊
11th Jun 2018, 2:05 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 7
Example int[] arr={1,2,3,4,5}; arr.length() is 5 because arr has 5 elements
10th Jun 2018, 1:15 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 3
Thanks muhd khairul
10th Jun 2018, 1:17 PM
Trevor Netshisaulu
Trevor Netshisaulu - avatar
+ 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.
10th Jun 2018, 8:18 PM
Nikhil Sharma
Nikhil Sharma - avatar
+ 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 }
23rd Aug 2020, 4:38 PM
ACID
ACID - avatar