Data Types

The basic data types which can be used in a high-level programming language  are as follows:

Data Type Description Examples
Boolean True or false (or any data that only has two possible values) TRUE or FALSE
YES or NO
Character Any character you see on the keyboard and some more besides... 'A', 'z', '8','?'
String A number of characters... "Hello World"
"Gerty Snoot"
Integer Whole numbers, positive and negative 23, -45, 0
Real All numbers including fractions 15.7, -19.25, 8

 

 
Storage

Data of different types uses different amounts of storage space in memory or on disk.

Data Type Storage Requirement
Boolean One BIT - a single binary digit 0 or 1

 

Character Usually one BYTE

Unicode characters (that allow characters from all the world's languages) use 2 bytes of storage.

 

String A string is a combination of characters. Storage requirement depends on the length of the string.

In most languages maximum string lengths are set.

 

Integer Storage requirements for integers depend on the range - the difference between the smallest and largest possible integers.

Generally integers stored in n BITs have a range of 2n values.

Example : Integers using 2 bytes (16 bits) have a range of 216 = 65536 values. 
In other words possible values are 0 to 65535...
...or -32768 to +32767

 

Real The data storage requirements of real numbers depends on the method used to store them. They will generally need more bytes of storage than integers.

 

 NB : It is good programming practice to choose data types that use less storage space if possible. For example, do not use real numbers if integers will do.

 

 

Operations on these data types

Data Type Basic Operations
Integer, Real All arithmetic functions +, -, *, / etc..

Relational operations

  • < less than
  • > greater than
  • <> not equal to
  • >= greater than or equal to
  • <= less than or equal to

(all these in the normal arithmetic sense)

Truncating - Limits the number of decimal places in a real number by chopping off unwanted digits

Rounding - Limits the number of significant digits in a number by taking the 'nearest' value with the required number of significant digits..

Example : 3.1415927

Truncated to 4 decimal places : 3.1415
Rounded to 4 decimal places : 3.1416

 

Character, Strings Use + for string concatenation - adding strings together.

eg 'Bull' + 'frog' = 'Bullfrog'

Use < , > etc in the alphabetical sense. These are all true...

  • 'Abacus' < 'Beetle'
  • 'Gannet' > 'Fish'
  • 'Barracuda' > 'Barnacle'
Boolean Usually used in conditional statements...'Flag' may be a Boolean variable....

if Flag = true then do...

or the equivalent statement...

if Flag then do ...