0

I don't get. what's the point of typing in a code to know the length when we can just count it

array lenght

25th Sep 2018, 10:59 AM
Emekxx🤓
Emekxx🤓 - avatar
4 Respostas
+ 8
you use it when you dont know the size of the array it could be when a user inputs a word and you split it inside an array and reverse it using a for loop you would never know how long that word is unless you use length.
25th Sep 2018, 11:05 AM
D_Stark
D_Stark - avatar
+ 5
Not all the containers store data in contiguous memory allocation. If you have a simple array it's all fine . But consider std::list for example..
25th Sep 2018, 12:43 PM
AZTECCO
AZTECCO - avatar
+ 1
because you can pass a function when the array is the right length, which doesn't have to be to print the size. Example: int test[6] if (test.length < 5) { doSomething(); }
25th Sep 2018, 11:04 AM
CodeMStr
CodeMStr - avatar
0
here is a question: what if you need to count the user’s input? you can’t know what the user will enter so you need a function that will count it for you. it is a great function for other purposes as well, for example, counting the length of items in an array or dictionary, etc.
26th Sep 2018, 12:15 AM
Xpl0it
Xpl0it - avatar