11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2Declaring Variables ConstantlyIn This Chapter Declaring variables Declaring different types of variables Using floating-point variables Declaring and using other variable typesThe most fundamental of all concepts in C++ is the variable — a variable islike a small box. You can store things in the box for later use, particularlynumbers. The concept of a variable is borrowed from mathematics. A statementsuch asx = 1stores the value 1 in the variable x. From that point forward, the mathematiciancan use the variable x in place of the constant 1 — until she changes thevalue of x to something else.Variables work the same way in C++. You can make the assignmentx = 1;From that point forward in the program, until the value of x is changed, anyreferences to x are the same as referencing 1. That is, the value of x is 1.Unfortunately, C++ has a few more concerns about variables than the mathematiciandoes. This chapter deals with the care and feeding of variables in C++.Declaring VariablesC++ saves numeric values in small storage boxes known as variables. Mathematiciansthrow variables around with abandon. A mathematician might (forexample) write down something like the following:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!