Data type

What does it mean by data type

  • Data type refers to the type of value a variable has and what type of mathematical, relational or logical operations can be applied without causing an error.(value, operation)

Primitive data types VS non-primitive data types

Primitive data types: The data types that are supported by computer hardware

  • Common primitive data types
  • integer
  • floating -point numbers
  • boolean
  • character

Non-primitive data type:

  • Data types that are build form other data types.

By value/ By reference.

Bulld-in data types VS user-defined data types

build-in data types

(1) The programming language defines the range of possible values that can be assigned to a variable when its type has been chosen

(2)

User defined data types

1. What does it mean by the user:

The programmer who use the certain programming language to write the programme

2. A user-defined data type is defined by the user:

The possible values; The operations that can be performed

3. Not all programming languages support user-defined data type

4. Once a user-defined data type is define, variables of this type can be decalred and uses.

Why is user-defined data types are necessary

  • No suitable data type is provide by the language used
  • The progeammer needs to specify a new data type to meet the requirement of the application/program.

Conposite data types VS non-composite data types

A composit data type or compound data type:

any data type that is constructured using primative data types and other composite types.

Non-composite data type:

Defined without other data types.

Example:

  • An integer is a non-composite
  • A record is a composited data type
  • A class is a composited data type

Non-composited data type VS enumerated data type:

A non-composite data type is one which has a definition which does

Enumerated data type

Two examples of enumerated data type definitions:

• pseudocode shows two examples of enumerated data type definitions:

TYPE Directions = (North, East, South, West)
TYPE TDays = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)

Note: the format of the definitions on our text book is not correct

Variables can be declared and assigned values, for example:

  • DECLARE Direction1 : TDirections
  • DECLARE StartDay: TDays
  • Direction1 & North
  • StartDay + Wednesday

• NOTE: The values of the enumerated type look like string values but they are not. The values must NOT be enclosed in quotes.

Composite user defined data types

A composite user-defined data type has a definition with reference to at least one other type.

Very important examples of composite user-defined data type.

  • The record data type (introduced in Chapter 13). Although there could be built-in record data types the expectation is for a record data type to be user-defined.
  • This allows the programmer to create record data types with components that precisely       match the data requirements of the particular
 program.
  • Note that Python is a language that does not support the use of a record data type.

The class.

  • A class is a data type which is used for an object in object-oriented programming.
  • For a given object-oriented programming language there are likely to be a number of built in classes.
  • However, if a programmer intends to utilize the benefits of the object-oriented approach, then the programmer will have to create a number of user-defined classes.

We’ll talk more details about class later in chapter 27

Pointer data type

A pointer variable is one for which the value is a reference to a memory location.

Example:

  • TYPE TintegerPointer =^ Integer
  • The ^ caret is used
  • A variable of TIntegerPointer stores a memory address of an Integer variable.

Pointer data type

 -Not all programming languages offer support for the use of a pointer data type. Those languages that do so will have their own version of the symbolism illustrated above with ^and@.

-Because arithmetic can be performed on pointer variables, it is possible to use pointer variables to construct dynamically varying data structures. For some programming languages it is necessary to declare an array with a large upper bound to ensure that the array is unlikely to be fully populated with values. If the language supports the use of a pointer variable, the size of an array can expand while a program is running. The details of how this can be done are beyond the scope of this discussion.

Set data type

-A set data type allows a program to create sets and to apply the mathematical operations defined in set theory. A set is a mathematical concept with important properties.

Features:

  1. -It contains a collection of data values.
  2. -There is no organization of the data values within the set. -> how the data values are organized is unveiled.
  3. -Duplicare values are not allowed.
  4. -Operations that can be performed on a ser include:
  5. – checking if a value exists in a set
  6. – adding a new data value
  7. – removing an existing data value
  8. – adding one set to another set.
  9. – get the intersection of 2 sets
  10. – get the union of 2 sets
  11. -Python offers the support of set data type.
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇