Chapter 4Arrays, Strings, and Pointers

  • How to use arrays
  • How to define and initialize arrays of different types
  • How to use the range-based for loop with an array
  • How to define and use multidimensional arrays
  • How to use pointers
  • How to define and initialize pointers of different types
  • The relationship between arrays and pointers
  • How to define references and some initial ideas on their uses

You can find the wrox.com code downloads for this chapter on the Download Code tab at www.wrox.com/go/beginningvisualc. The code is in the Chapter 4 download and individually named according to the names throughout the chapter.

HANDLING MULTIPLE DATA VALUES OF THE SAME TYPE

You already know how to define and initialize variables of various types that each holds a single item of information; I’ll refer to single items of data as data elements. The most obvious extension to the idea of a variable is to be able to reference several data elements of a particular type with a single variable name. This would enable you to handle applications of a much broader scope.

Let’s consider an example. Suppose that you needed to write a payroll program. Using a separate variable for each individual’s pay, tax liability, and so on, would be an uphill task to say the least. A more convenient way to handle such a problem would be to reference an employee by some kind of generic name — employeeName to take an imaginative example ...

Get Ivor Horton's Beginning Visual C++ 2013 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.