Skip to content

Data Types

標準~22 min5 terms0 past questions

Goals of this unit

  • Choose the right data type based on the kind of value to be handled.
  • Explain, using the values each one holds, how types for numbers differ from types for truth values and characters.
  • Explain that the result of a comparison is a Boolean type value and is used to branch processing.
Terms at a glance (5)
TermIn one lineExample values
データ型A classification that sets the kind of a value and the operations allowed on itUmbrella term for the types below
整数型A type for whole numbers with no fractional part-3, 0, 42
実数型A type for numbers that can have digits after the decimal point2.5, -0.75
論理型A type that holds either true or falsetrue, false
文字型A type for a single character'A', '7', 'あ'

Terms

A data type (データ型) is a classification that fixes what kind of data a variable or value represents, along with the range of values it can take and the operations it allows.

  • Data types (basic types in this unit)
    • Integer type
    • Real type
    • Boolean type
    • Character type

Once the type is set, it determines how the value is stored in memory, how large a range of values fits, and which operations can be applied. This unit covers 4 basic types: integer, real, Boolean and character. Giving each variable a type makes it easier to catch the mistake of storing a value of the wrong kind.

AnalogyIt is like labeling each drawer of a filing cabinet with the kind of item it may hold. Because of that rule, you always know how to handle whatever you take out.

How to rememberThe Japanese 型 (kata) is simply a translation of "type", which means a kind or category.

Exam points

  • Mix-upData type (データ型) is the collective name for all the individual types, while the integer type (整数型) and the character type (文字型) are each one type within it.

整数型Integer Type

Open in glossary 整数型

The integer type (整数型) is a data type for whole numbers with no fractional part, negative numbers included.

It suits values that never have a fraction, such as counts, repetitions, or the position number of an element in an array. When one integer is divided by another, it can also be used to get the quotient and the remainder as integers.

AnalogyThink of the steps of a staircase. There is a first step and a second step, but no step 1.5.

How to remember"Integer" comes from a Latin word meaning "untouched, whole".

Exam points

  • Mix-upThe values an integer type (整数型) can hold have an upper and a lower limit, and that range depends on the language implementation. A calculation result outside the range cannot be represented correctly.

The real type (実数型) is a data type for numbers that can have digits after the decimal point.

It is used for values with fractions, such as lengths, averages and ratios. Inside the computer it is usually stored as a floating-point number, so a value like 0.1 that has no exact binary form carries a tiny error.

AnalogyIt is like reading a length that falls between the marks on a ruler. The reading may still be off by a very small amount.

How to remember"Floating" in floating-point refers to the decimal point moving its position to fit the size of the number.

Exam points

  • Mix-upThe real type (実数型) and the integer type (整数型) both represent numbers, and they differ in whether a fractional part is allowed.

Integer Type vs. Real Type

AspectInteger TypeReal Type
Key differenceValues heldWhole numbers with no fractional partNumbers with digits after the decimal point
Examples-3, 0, 422.5, -0.75
Internal formStored exactly as a binary integerUsually stored as a floating-point number, which may carry an error
Suited toCounts, repetitions, positionsLengths, averages, ratios

論理型Boolean Type

Open in glossary 論理型

The Boolean type (論理型) is a data type that takes only one of 2 values, true or false.

ComparisonResult (Boolean value)
8 > 5true
4 = 9false
6 ≦ 6true

An expression that compares sizes or equality yields a Boolean value, which serves as the condition that steers processing in selection and repetition. In Japanese it is also called Boolean type (ブール型), while the formal term 論理型 literally means "logical type".

AnalogyThink of a light switch. It is either on or off, with nothing in between.

How to remember"Boolean" comes from George Boole, the mathematician who turned calculations with true and false into a system.

Exam points

  • Mix-upThe Boolean type (論理型) holds truth itself as its value, and it is a separate type from the number or character types being compared.

文字型Character Type

Open in glossary 文字型

The character type (文字型) is a data type whose value is a single character, such as a letter, digit, symbol or kana.

Inside the computer, each character is represented by a number called a character code. A value made of several characters in a row is handled as a string; pseudo-language and similar notations give it a separate type, the string type.

AnalogyIt is like a single piece of movable type. Even a piece shaped like a digit is a symbol for printing, not a number for calculating.

How to rememberMany programming languages abbreviate "character" to char in code.

Exam points

  • Mix-upThe character '5' is a character represented by a character code (文字コード), a different value from the number 5. To calculate with it as a number, convert it to a numeric type first.

Integer Type vs. Character Type

AspectInteger TypeCharacter Type
Values that look alikeThe number 5The character '5'
Internal formThe size of the number in binaryThe number assigned by the character code
Key differenceArithmeticCan be used in arithmetic as isMust be converted to a numeric type first

Key points

  • Choosing a data type fixes how a value is stored, what range of values fits, and which operations are available.
  • The integer type has upper and lower limits on its values, and the range depends on the implementation.
  • The real type is usually stored as a floating-point number, so some values carry a tiny error.
  • The result of a comparison is a Boolean value, used as the condition for selection and repetition.
  • The character type holds one character, and a value made of several characters is handled as a string.

All past questions in this topic