C++ ArraysLike other programming languages, array in C++ is a group of similar types of elements that have contiguous memory location. In C++ std::array is a container that encapsulates fixed size arrays. In C++, array index starts from 0. We can store only fixed set of elements in C++ array. Advantages of C++ Array
Disadvantages of C++ Array
C++ Array TypesThere are 2 types of arrays in C++ programming:
C++ Single Dimensional ArrayLet's see a simple example of C++ array, where we are going to create, initialize and traverse array. Output:/p> 10 0 20 0 30 C++ Array Example: Traversal using foreach loopWe can also traverse the array elements using foreach loop. It returns array element one by one. Output: 10 20 30 40 50 Next TopicC++ Passing Array to Function
|