0% found this document useful (0 votes)
23 views17 pages

Lecture 1.7 - Introduction To Datatypes

Uploaded by

parasmahajan257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views17 pages

Lecture 1.7 - Introduction To Datatypes

Uploaded by

parasmahajan257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction to Datatypes

Sanity of data: what we observed


• We organised our data set into cards, each storing one data item
• Each card had a number of elements, e.g.:
• numbers (e.g. marks)
• sequence of characters (e.g. name, bill item, word etc)
• We observed that there were restrictions on the values each element
can take:
• for example marks has to lie between 0 and 100
• name cannot have funny characters
• Constraints on the kinds of operations that can be performed:
• addition of marks is possible
• but multiplication of marks does not make sense !
• compare one name with another to generate a boolean type (True or False)
• but cannot add a name with another !
This leads us to the concept of a Data Type ...
• By associating a Data Type (or simply Type) with a data element,
we can tell the computer (or another person) how we intend to use a
data element:
• What are the values (or range of values) that the element can take ?
• What are the operations that can be performed on the data element ?

• When we specify that a variable is of a specific type, we are


describing the constraints placed on that variable in terms of the
values it can store, and the operations that are permitted on it
Basic Data Types
Basic Data Types

Boolean
Basic Data Types

Boolean

Has only two values:


True, False
Basic Data Types

Boolean

Has only two values:


True, False
Operation Result type
AND, OR Boolean
Basic Data Types

Boolean Integer

Has only two values:


True, False
Operation Result type
AND, OR Boolean
Basic Data Types

Boolean Integer

Has only two values: Range of values is:


True, False ... , -3, -2, -1, 0, 1, 2, 3, ...
Operation Result type
AND, OR Boolean
Basic Data Types

Boolean Integer

Has only two values: Range of values is:


True, False ... , -3, -2, -1, 0, 1, 2, 3, ...
Operation Result type Operation Result type
AND, OR Boolean +, - , ×, ÷ Integer
Basic Data Types

Boolean Integer

Has only two values: Range of values is:


True, False ... , -3, -2, -1, 0, 1, 2, 3, ...
Operation Result type Operation Result type
AND, OR Boolean +, - , ×, ÷ Integer

There are constraints on division (÷)


For result to be integer, first number has to be divisible by
second (e.g. 21 ÷ 7 = 3)
Or we change the definition to take only the quotient and
drop the remainder (e.g. 22 ÷ 7 = 3)
Basic Data Types

Boolean Integer

Has only two values: Range of values is:


True, False ... , -3, -2, -1, 0, 1, 2, 3, ...
Operation Result type Operation Result type
AND, OR Boolean +, - , ×, ÷ Integer
<, >, = Boolean
Character Data Type
Values ?
Character
Character Data Type
Values - alphanumeric:
Character A B ... Z a b ... z 0 1 ... 9
Special characters:
. , ; : * / & % $ # @ ! ...
Character Data Type
Values - alphanumeric:
Character A B ... Z a b ... z 0 1 ... 9
Special characters:
. , ; : * / & % $ # @ ! ...
Operation Result type
?
Character Data Type
Values - alphanumeric:
Character A B ... Z a b ... z 0 1 ... 9
Special characters:
. , ; : * / & % $ # @ ! ...
Operation Result type
= Boolean

You might also like