Type Casting

Type Casting

A type cast explicitly converts a value of one type to another type.

static_cast(expression)

Ex: If myIntVar is 7, then static_cast(myIntVar) converts int 7 to double 7.0.

Integer numeric data types.
Declaration Size Supported number range Standard-defined minimum size
char myVar; 8 bits -128 to 127 8 bits
short myVar; 16 bits -32,768 to 32,767 16 bits
long myVar; 32 bits -2,147,483,648 to 2,147,483,647 32 bits
long long myVar; 64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 64 bits
int myVar; 32 bits -2,147,483,648 to 2,147,483,647 16 bits

Floating-Point Numeric Data Types
Declaration Size Supported number range
float x; 32 bits -3.4×1038 to 3.4*1038
double x; 64 bits -1.7×10308 to 1.7*10308

Unsigned Integer Data Types
Declaration Size Supported number range Standard-defined minimum size
unsigned char myVar; 8 bits 0 to 255 8 bits
unsigned short myVar; 16 bits 0 to 65,535 16 bits
unsigned long myVar; 32 bits 0 to 4,294,967,295 32 bits
unsigned long long myVar; 64 bits 0 to 184,467,440,737,095,551,615 64 bits
unsigned int myVar; 32 bits 0 to 4,294,967,295 16 bits