Chapter 02 Description of Simple Data
1. Data Type
Data type is composed of value set and operation set and can be divided into primitive data type and compound data type.
In terms of the requirement of declaration on data type, programming language can be classified as:
- Statically typed language call for declaration on type of each data and usually executed by compiling.
- Dynamically typed language doesn’t need to claim data type and usually executed by interpreting.
2. Fundamental Data Type
Fundamental data type is predefined by the language and is also called standard type or built-in type.
Fundamental data type is mostly arithmetic type.
2.1 Integral Type
1. integer type
int
short int
orshort
, ranging from -32768 to 32767, occupying 2 byte.long int
orlong
Range(short int) <= Range(int) <= Range(long int)
Unsigned integer is twice the range of usual integer type.
2. character type
char
Character is stored in computer as ASCII, which means American Standard Code for Information Interchange.
3. boolean type
bool
Boolean type has only two value:
true
orfalse
, whiletrue
is often stored as1
andfalse
is often stored as0
.
2.2 Real Type
Real type is also called float point type in C++.
float
double
long double
Range(float) < Range(double) <= Range(long double)
2.3 Void Type
void
Void type is used to describe the type of the return value of a function that actually doesn’t return a value.
2.4 Some Operations
-
We can use function
sizeof(<type-name>)
to get the space(byte) that needed to store this type of data. -
We can use keyword
typedef <existing-type-name> <new-name>
to rename an existing type, for example:typedef unsigned int Uint; //Remember that typedef just rename an existing data type, rather than creating a new data type.