Use container classes rather than simple arrays?
I have recently finished studying basics of C++ programming language. Though this was my first programming language I found it to be very easy. As I have completed C++, there is an assignment that I have to work on. One question in the assignments asks explanation as to why container classes are used rather than simple arrays? Provide some of your opinions on this.
Re: Use container classes rather than simple arrays?
The main reason why software programmers prefer container classes over simple arrays of C++ is that container classes are considered to be more productive than simple arrays. Another major reason is that a more powerfully built program can be written using container classes instead of the simple arrays.
Lesser bugs with container classes
By many it is been noted that programs coded in C++ using the container classes are containing lesser number of bugs as compared to programs written using arrays. Also programs written with container classes are more secured. One of the popularly noted problem with arrays is that subscripts of arrays go unchecked and are not tracked down for out of bound arrays.
Container classes provide easy memory management
The storage of Array elements is done on Heap Memory. There is a pitfall for allocating heap storage which is that you will have to assign a code that will always de-allocate the memory space on heap. The advantage with container classes is that the process of memory management is taken care automatically. Thus to have a more easy memory management it is recommended to use Container classes over arrays.
Re: Use container classes rather than simple arrays?
Consider an instance where an element has to be inserted in an array. This element has to inserted in between. And this is not possible in array. But this is feasible with container classes. Another characteristic of container class is that the programmer can choose whether to pass by value or pass by reference. But with arrays this is restricted.