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
4 odpowiedzi
+ 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.
+ 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..
+ 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();
}
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.