11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Declaring Variable TypesChapter 2: Declaring Variables Constantly 33So far this chapter has been trumpeting that variables must be declared andthat they must be assigned a type. Fortunately (ta-dah!), C++ provides a numberof different variable types. See Table 2-1 for a list of variables, their advantages,and limitations.Table 2-1Variable Example PurposeC++ Variablesint 1 A simple counting number, either positive ornegative.unsigned int 1U A counting number that’s only non-negative.long 10L A potentially larger version of int. There isno difference between long and int withDev-C++ and Microsoft Visual C++.NET.unsigned long 10ULA nonnegative long integer.float 1.0F A single precision real number. This smallerversion takes less memory than a doublebut has less accuracy and a smaller range.double 1.0 A standard floating-point variable.char ‘c’ A single char variable stores a single alphabeticor digital character. Not suitable forarithmetic.string “this is A string of characters forms a sentence ora string” phrase.bool true The only other value is false. No I mean, it’sreally false. Logically false. Not “false” asin fake or ersatz or . . . never mind.It may seem odd that the standard floating length variable is called doublewhile the “off size” is float. In days gone by, memory was an expensive asset —you could reap significant space savings by using a float variable. This is nolonger the case. That, combined with the fact that modern processors performdouble precision calculations at the same speed as float, makes the doublethe default. Bigger is better, after all.

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

Saved successfully!

Ooh no, something went wrong!