signed int

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name signed int
Ontology
Released 1983

Whole numbers.png


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.

Other C++ data types of the same size

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
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox