Definition of Int in C, C++ and C#

An int variable contains only whole numbers

Int is short for "integer." Int is a fundamental variable 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.

Int Limitations

Only negative and positive whole numbers can be stored in int variables. Therefore, for example, 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 usually is 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 also can 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 than other types 
  • Has faster arithmetic
  • Uses only whole numbers
  • Uses caches and data transfer bandwidth more efficiently

Float and double types:

  • Use twice as much memory
  • Can contain a decimal point
  • 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.