Definition of Int

An int variable contains only whole numbers

What Is Int in Computer Programming?

Int is short for "integer." Int is a fundamental type built into the compiler and used to define numeric variables holding whole numbers. C, C++, C# and many other programming languages recognize int as a type. Other data types include float and double.

Because only negative and positive whole numbers can be stored in int variables, 27, 4908 and -6575 are valid int entries, but 5.6 is not.

Numbers with fractional parts require a float or double type variable, both of which can contain decimal points.

The size of number that can be stored in int is usually not defined in the language, but instead depends on the computer running the program. In C#, int is 32 bits, so the range of values is from -2,147,483,648 to 2,147,483,647. If larger values are required, the double type can be used.

What Is Nullable Int?

Nullable int has the same range of values as int, but it can store null in addition to whole numbers. You can assign a value to nullable int just as you would for int. You can also assign a null value. Nullable int can be useful when you want to add another state (invalid or uninitialized) to a value type. Nullable int cannot be used in loops. Loop variables must always be declared as int.

Int vs. Float and Double

Int is similar to the float and double types, but they serve different purposes.

Int takes up less space, the arithmetic is usually faster, uses only whole numbers, and it uses caches and data transfer bandwidth more efficiently. Float and double types use twice as much memory, can contain a decimal point, and can contain more characters. The difference between float and double types lies in the range of values.

The range of double is twice that of float, and it accommodates more digits.