Signed int
(Created page with "{{FormatInfo | name = signed int | formattype = electronic | subcat = Data types | subcat2 = C++ data types | subcat3 = | subcat4 =...") |
|||
(2 intermediate revisions by one user not shown) | |||
Line 16: | Line 16: | ||
| uniform type = | | uniform type = | ||
| conforms to = | | conforms to = | ||
− | | released = | + | | released = 1983 |
− | | image = | + | | image = Whole numbers.png |
| caption = | | caption = | ||
}} | }} | ||
Line 27: | Line 27: | ||
'''int''' can safely store values -2¹⁵ – 2¹⁵-1, if the value gets too large or too small, a roll over can take place. While the fact of a roll over is a guarantee at some point, a coder cannot assume that it will happen in a specific place, INT_MIN and INT_MAX constants from <climits> library can be used to determine that. Many implementations push int into a 32-bit range. | '''int''' can safely store values -2¹⁵ – 2¹⁵-1, if the value gets too large or too small, a roll over can take place. While the fact of a roll over is a guarantee at some point, a coder cannot assume that it will happen in a specific place, INT_MIN and INT_MAX constants from <climits> library can be used to determine that. Many implementations push int into a 32-bit range. | ||
+ | |||
+ | Unlike the early versions of C (on which C++ is based) int is '''not''' a default type, in fact no default types exist at all. | ||
==Other C++ data types of the same size== | ==Other C++ data types of the same size== | ||
* [[unsigned int]] | * [[unsigned int]] | ||
* [[char16_t]] or [[char32_t]] (depending upon implementation) | * [[char16_t]] or [[char32_t]] (depending upon implementation) | ||
− | * [[signed short int|short]] | + | * [[signed short int|short]] or [[signed long int|long]] both can be equal to int, on most implementations at least one of them is. |
==Other C++ data types storing signed integers== | ==Other C++ data types storing signed integers== |
Latest revision as of 19:34, 8 June 2015
C++ signed int will take at least 16 bits of memory to hold and cannot be less than signed short int in any specific implementation; it can, however, differ from compiler to compiler. It usually gets stored as two's complement integer, but it is not a requirement of the standard. It is the standard way to represent an integer in C++, function main
returns int, even though in practice unsigned char would have been more than sufficient. An integer literal gets interpreted as int, unless followed by extra characters to symbolise that it's something else.
It can be shortened during declaration or conversion to signed or int, int being the most common.
int can safely store values -2¹⁵ – 2¹⁵-1, if the value gets too large or too small, a roll over can take place. While the fact of a roll over is a guarantee at some point, a coder cannot assume that it will happen in a specific place, INT_MIN and INT_MAX constants from <climits> library can be used to determine that. Many implementations push int into a 32-bit range.
Unlike the early versions of C (on which C++ is based) int is not a default type, in fact no default types exist at all.
[edit] Other C++ data types of the same size
- unsigned int
- char16_t or char32_t (depending upon implementation)
- short or long both can be equal to int, on most implementations at least one of them is.
[edit] Other C++ data types storing signed integers
- signed char at least 8 bits
- short not less than 16 bits, not smaller than signed char
- long not less than 32 bits, not smaller than int
- long long not less than 64 bits, not smaller than long