Q:

Why don’t list or array have a capacity member

0

Why don’t list or array have a capacity member? 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

A `list` does not support random access, and element of `list` is stored seperately in memory. There is no need to reallocate its elements, and thus no need to preallocate memory. So the "`capacity`" of a `list` is the same with its `size`.

An `array` has a fixed size, there is also no need to reallocate its elements, and thus no need to preallocate memory. So the "`capacity`" of an `array` is the same with its `size` too.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now