Chapter 2Data, Variables, and Calculations

  • C++ program structure
  • Namespaces
  • Variables in C++
  • Defining variables and constants
  • Basic input from the keyboard and output to the screen
  • Performing arithmetic calculations
  • Casting operands
  • Variable scope
  • What the auto keyword does
  • How to discover the type of an expression

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 2 download and files are individually named according to the names throughout the chapter.

THE STRUCTURE OF A C++ PROGRAM

Console applications are programs that read data from the command line and output results to the command line. All the examples that you’ll write to understand how the C++ language works will be console programs. This avoids having to dig into the complexities of creating and managing Windows applications before you have enough knowledge of how they work. You will be able to focus entirely on C++. After you have mastered that, you’ll be ready to deal with creating and managing Windows applications and the sacks of code that it involves. I’ll start by explaining how console programs are structured.

A C++ program consists of one or more functions. A function is a self-contained block of code with a unique name that you use to identify the function when you want to execute it. Chapter 1 includes an example of a Win32 console ...

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.