Home >Backend Development >C#.Net Tutorial >What is Int in C, C++ and C#
Int, the abbreviation of "integer", is the basic variable type built into the compiler, used to define numeric variables containing integers. Other data types include float and double.
C, C++, C# and many other programming languages recognize int as a data type.
In C, here is how to declare an integer variable:
int a = 7;
Limitations of Int
Only integers can be stored in int variables, but Since they can store positive and negative numbers, they are also considered signed.
For example, 27, 4908 and -6575 are valid int entries, but 5.6 and b are not. Numbers with a decimal part require float or double variables, both of which can contain a decimal point.
The size of a number that can be stored in an int is usually not defined in the language but depends on the computer running the program. In C#, int is 32 bits, so the range of values is -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 integer)?
Nullable int has the same value range as int, but in addition to integers, it can also store null. You can assign a value to a nullable int just like you would an int, or you can assign a value to null.
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 because 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 integers
More efficient use of cache and data transfer bandwidth
Float and double types:
Use twice the memory
Can include decimal points
Can contain more characters
The difference between float and double types is the range of values. The range of double is twice that of float, and it can hold more numbers.
Note: INT is also used as a formula in Microsoft Excel to round numbers down, but it has nothing to do with int as described in this page.
The above is the detailed content of What is Int in C, C++ and C#. For more information, please follow other related articles on the PHP Chinese website!