15.04.2018 Views

programming-for-dummies

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

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

Declaring Variables 527<br />

All integer types (int, short, and long) can also be signed or unsigned.<br />

Signed data types can represent positive or negative numbers whereas<br />

unsigned data types can represent only positive numbers.<br />

Book VI<br />

Chapter 1<br />

To define positive values <strong>for</strong> an integer variable, you could do this:<br />

unsigned int variablename;<br />

The signed declaration isn’t necessary because<br />

C and C++<br />

signed long variablename;<br />

is identical to<br />

long variablename;<br />

Table 1-1 shows the range of values common integer data types in C/C++ can<br />

hold.<br />

Table 1-1 Typical Storage and Range Limitations of C/C++ Integer Data Types<br />

Data Type Number of Bytes Range<br />

short 2 Signed: –32,768 to 32,767<br />

Unsigned: 0 to 65,535<br />

int 4 Signed: –2,147,483–3,648 to<br />

2,147,483,647<br />

Unsigned: 0 to 4,294,967,295<br />

long 4 or 8 Signed: –2,147,483,648 to<br />

2,147,483,647<br />

Unsigned: 0 to 4,294,967,295<br />

The exact number of bytes and range of all integer data types depends on<br />

the compiler used and the operating system, such as whether you’re using a<br />

32-bit or a 64-bit operating system. With many compilers, the range of values<br />

is identical between int and long data types.<br />

Declaring floating point data types<br />

Floating point values represent decimal values, such as 3.158 or –9.4106. Just<br />

as you can limit the range of integer values a variable can hold, so can you<br />

limit the range of floating point values a variable can hold.<br />

The three types of floating data types are float, double, and long double, as<br />

shown in Table 1-2.

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

Saved successfully!

Ooh no, something went wrong!