Module CG1.3
Data Types and
Data Structures
Page Index to sections in CG1.3 Data types & data structures
Describe the different primitive data types: Boolean, character, string, integer and real
3
Describe the storage requirements for each data type
3
Describe the manipulation of records and arrays up to two dimensions
8
Identify and justify the correct data structure (record or array) for a given situation
10
Describe the different primitive data types (Boolean, character, string, integer and real).
Describe the storage requirements for each data type.
Introduction to Data Types
All programs of a non-trivial nature involve the storage of information (data). Each individual …show more content…
Each character requires one byte as it is usually stored as an ASCII character. Notice that a digit such as 8 could be held as either a character, an integer or even a real. If any calculations are going to take place on the value then it should be held as either an integer or a real. If the calculation will never result in it being extremely large or gaining decimal places then an integer should be used.
4. Boolean
A boolean can only be one of two values, either true or false. A boolean only really needs one bit (an eighth of a byte) to hold true (1) or false (0) but strangely, Visual Basic uses two bytes to hold a boolean variable.
5. String
Strictly speaking a string is not a primitive data type as it is derived from the character data type. A string is simply a list of characters that allow words, sentences, etc. to be dealt with. Strings are stored in memory in one of three ways as detailed below. Some programming languages give the programmer a choice as to which they want to use. The choice often depends on the particular requirements at the time.
a) Fixed Length Strings: A fixed length string allocates a maximum length to each string. Thus if we declared a string as being length 10 then the word “Dog” would be held as:
D
O