Signed int
(Created page with "{{FormatInfo | name = signed int | formattype = electronic | subcat = Data types | subcat2 = C++ data types | subcat3 = | subcat4 =...") |
(released) |
||
Line 16: | Line 16: | ||
| uniform type = | | uniform type = | ||
| conforms to = | | conforms to = | ||
− | | released = | + | | released = 1983 |
| image = | | image = | ||
| caption = | | caption = |
Revision as of 07:04, 13 May 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.
Other C++ data types of the same size
- unsigned int
- char16_t or char32_t (depending upon implementation)
- short (it is less than or equal to signed int, in many implementations they are equal, but it is not a requirement)
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