C++ Data Types - C++ Data Type

C++ examples for Data Type:Introduction

Introduction

TYPE DESCRIPTION RANGE
char 1-byte integer (used to hold ASCII character value)0 to 255
unsigned char 1-byte unsigned integer0 to 255
signed char 1-byte signed integer -128 to 127
short 2-byte integer -32,768 to 32, 767
unsigned short2-byte unsigned integer0 to 65,535
Int 4-byte integer (but same as short on 16-bit systems) Approx. +/- 2 billion
unsigned int 4-byte unsigned integer (but same as unsigned short on 16-bit systems) Approx. 4 billion
long 4-byte integer Approx. +/- 2 billion
unsigned long 4-byte unsigned integerApprox. 4 billion
bool Integer in which all nonzero values are converted to true (1); also holds false (0) (ANSI) true or false
wchar_t Wide character, for holding Unicode characters (ANSI) Same as unsigned int
long long 64-bit signed integer (C++11) Approx. +/-9 x 10 to the 18th
unsigned long long64-bit unsigned integer (C++11)Approx. 1.8 x 10 to the 19th
float Single-precision floating point3.4 x 10 to the 38th
doubleDouble-precision floating point1.8 x 10 to the 308th
long double Extra-wide double-precision (ANSI) At least as great as double

Data Types of Numeric Literals

The default numeric format is decimal (base 10).

The default storage for whole numbers is int type.

The 0x prefix specifies hexadecimal (base 16). A leading 0 specifies octal (base 8). The 0b prefix specifies binary radix (base 2).

Scientific notation indicates floating-point format: The literal is stored in double format.

A decimal point followed by .0 indicates floating-point format stored in double format.

Here's an example:

int a = 0xff;               // Assign 1111 1111 (256) to a.
int b = 0100;               // Assign octal 100 (64) to b.
double x = 3.14;   // Assign flt. pt. number
double y = 3.0;    // This also assigns flt pt.
double z = 1.6e5;  // Use of scientific notation:
//  1.6 times 10 to the fifth

The L suffix indicates storage of an integer in long int format.

The U suffix indicates storage of an as unsigned int.

The F suffix indicates storage in float format (4-byte floating point) rather than double (8-byte floating point).

If long long is supported, then the LL and ULL suffixes are supported for long long and unsigned long long formats, respectively.


Related Tutorials