Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Programming Fundamentals/Data Types

From Wikibooks, open books for an open world
<Programming Fundamentals
Thelatest reviewed version waschecked on18 February 2021. There aretemplate/file changes awaiting review.

Overview

[edit |edit source]

A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data, including integer, real, character or string, and Boolean.

Discussion

[edit |edit source]

Our interactions (inputs and outputs) with a program are treated in many languages as a stream of bytes. These bytes represent data that can be interpreted as representing values that we understand. Additionally, within a program, we process this data in various ways such as adding them up or sorting them. This data comes in different forms. Examples include:

  • your name – a string of characters
  • your age – usually an integer
  • the amount of money in your pocket – usually a value measured in dollars and cents (something with a fractional part)

A major part of understanding how to design and code programs is centered in understanding the types of data that we want to manipulate and how to manipulate that data.

Common data types include:

Data TypeRepresentsExamples
integerwhole numbers-5,0,123
floating point (real)fractional numbers-87.5,0.0,3.14159
stringA sequence of characters"Hello world!"
Booleanlogical true or falsetrue,false
nothingno datanull

The common data types usually exist in most programming languages and act or behave similarly from language to language. Additional complex and/or composite data types may exist and vary from language to language.

Pseudocode

[edit |edit source]
Function Main    ... This program demonstrates variables, literal constants, and data types.    Declare Integer i    Declare Real r    Declare String s    Declare Boolean b        Assign i = 1234567890    Assign r = 1.23456789012345    Assign s = "string"    Assign b = true    Output "Integer i = " & i    Output "Real r = " & r    Output "String s = " & s    Output "Boolean b = " & bEnd

Output

[edit |edit source]
Integer i = 1234567890Real r = 1.23456789012345String s = stringBoolean b = true

Flowchart

[edit |edit source]

Data types flowchart

Key Terms

[edit |edit source]
Boolean
A data type representing logical true or false.
Data types
Defines a set of values and a set of operations that can be applied on those values.
Floating point
A data type representing numbers with fractional parts.
Integer
A data type representing whole numbers.
String
A data type representing a sequence of characters.

References

[edit |edit source]
← Identifier Names
Programming Fundamentals
Integer Data Type →
Retrieved from "https://en.wikibooks.org/w/index.php?title=Programming_Fundamentals/Data_Types&oldid=3811291"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp