The Fundamental Data Types


C++ has a built-in set of data types, as shown in the table below.

Type

Description

Comments

bool

A Boolean type that can contain the values true or false

char

A character type that can hold ASCII values

Values can range from -128 to +127.

short

An integral type; stores whole numbers

Values can range from -32,768 to +32,767. An unsigned short can range from 0 to 65,535.

int

An integral type; stores whole numbers

Values can range from -2,147,483,648 to 2,147,483,647. An unsigned int can range from 0 to 4,294,967,295.

long

An integral type like int, except on many compilers, it’s twice the size

In Microsoft Visual C++, the long is the same size as the int. And therefore it can only store the same range of values.

__int8

A Microsoft-specific integral type, synonymous with the char data type

__int16

A Microsoft-specific integral type, synonymous with the short data type

__int32

A Microsoft-specific integral type, synonymous with the int data type

__int64

A Microsoft-specific integral type that stores whole numbers

Values can range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

float

Stores floating point numbers, for example, 3.7

In Visual C++, the float stores up to seven decimal places. The range of values is 3.4E+/-38.

double

Stores floating point numbers like the float but with greater precision and more accuracy

The double can store up to 15 decimal places. The range of values is 1.7E+/-308

wchar_t

A wide character or multibyte character type

From these built-in types, you can construct other types, as we’ll see in this chapter:

  • Pointer types, for example, int*

  • Array types, for example, int[]

  • Reference types, for example, double&

Or you can construct user-defined types by creating data structures and classes. Classes were introduced in Chapter 2 and will be elaborated upon in Chapter 6. Structs are covered in Chapter 9.




Microsoft Visual C++  .NET(c) Step by Step
Microsoft Visual C++ .NET(c) Step by Step
ISBN: 735615675
EAN: N/A
Year: 2003
Pages: 208

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net