15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

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

578<br />

Declaring Variables<br />

If you only want to store a single character, you can use the Char keyword,<br />

such as<br />

Var<br />

Variablename1 : Char;<br />

To assign values to a variable in Pascal, use the colon and the equal sign<br />

symbols, such as :=, instead of just the equal sign (=) like other <strong>programming</strong><br />

languages.<br />

Declaring integer data types<br />

Whole numbers represent integers such as 349, –152, or 41. A whole number<br />

can be positive or negative. The most common type of integer data type is<br />

Integer and is used as follows:<br />

Var<br />

Variablename1 : Integer;<br />

To accept different ranges of integer values, Pascal offers several integer<br />

data types. For example, if a variable needs only to hold a positive value, you<br />

can declare it as a Byte data type, such as<br />

Var<br />

Variablename1 : Byte;<br />

Besides limiting the range of integer values, different integer data types also<br />

require different amounts of memory to store that data. The greater the<br />

range of values you need to store, the more memory needed (measured in<br />

bytes). The smaller the range of values, the less memory required. Table 4-1<br />

shows different integer data types, the memory needed, and the range of<br />

values they can hold.<br />

Table 4-1<br />

Pascal Integer Data Types<br />

Data Type Number of Bytes Range<br />

Byte 1 0 to 255<br />

ShortInt 1 –128 to 127<br />

Word 2 0 to 65,535<br />

SmallInt 2 –32,768 to 32,767<br />

Integer 4 –2,147,483,648 to 2,147,483,647<br />

LongWord 4 0 to 4,294,967,295<br />

Int64 8 –9,223,372,036,854,775,808 to<br />

9,223,372,036,854,775,807

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

Saved successfully!

Ooh no, something went wrong!