The most basic of the primitive types are the number types. These include integral numeric types (which represent whole numbers, like 1, 67, 1957321, 8, and so on) and _floating-point numeric types _(which represent non-whole numbers such as 1.2, 6.99, 8234.66, and so on).
Of the integral numeric types, the type int
is the default and most common. int
represents a 32-bit integer, with a positive or negative value.
int five = 5;
int thirteenHundred = 1300;
int negativeForty = -40;
int intMaxValue = int.MaxValue; //(2^32 - 1)
The type int
is used for many kinds of variables, including math, counters, and iterators.
short
, long
, and byte
are all integral numeric types, like int
. However, they represent different ranges of values.
A short
represents a 16-bit integer:
short three = 3;
short negativeOneHundred = -100;
short shortMaxValue = short.MaxValue; //(2^16 - 1)
A long
represents a 64-bit integer:
long fifty = 50;
long longMaxValue = long.MaxValue; //(2^64 - 1)
Finally, a byte
is a 8-bit integer that only represents positive values.
byte four = 4;
byte byteMaxValue = byte.MaxValue; //(2^8 - 1)
#c# #c++