5 Hip hip array – C++ arrays

 

This chapter covers

  • Exploring the concept of object collection
  • Introduction to Arrays and their role in C++
  • Working with single and multi-dimensional arrays
  • Unraveling the std::array container

Up to this point in your C++ journey, you learned how to work only with single objects (variables) in your code. In this chapter, you will learn how to work with multiple objects, generally known as collections.

We start by explaining how different data structures are used to manage and manipulate collections of objects, and the general concept of collections. In this chapter, we also introduce the basic concept of C++ containers, which are designed to simplify the task of managing collections of objects by providing a set of methods and operators that allow you to insert, remove, search, and traverse the elements stored in them.

You will then learn about arrays, which are a fixed-size list of elements. We start with C-style arrays, which are still widely used in C++ - you will learn all about their role, and how and when to implement them in your code. You will also learn about multidimensional arrays, which are a more complex grid (matrix) of two arrays or more. You will practice an interesting program that emulates a spreadsheet, using a multidimensional array.

5.1 Because you’re not alone – working with collections of elements

 
 
 
 

5.2 Array of sunshine: The concept of arrays

 
 

5.2.1 C-style arrays - Declaring and initializing them

 
 
 

5.2.2 From zero to index: why the index matters

 
 
 

5.2.3 While loops and arrays – the power couple

 
 
 

5.2.4 For the love of array: For loops and arrays

 

5.2.5 Multi-dimensional arrays – simplify visually related arrays

 
 
 

5.2.6 Code practice: Write a two-dimensional array Spreadsheet-like code

 
 

5.2.7 std::array – more powerful than C-style array

 
 
 
 

5.2.8 Size meets Mr. T – indexing our array using size_t

 
 
 
 

5.2.9 Additional std::array methods

 
 

5.2.10 Working with multidimensional std::array

 
 

5.3 Final exercise – write a rock-paper-scissors game

 
 

5.4 Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest