Integer
An integer is a number without a fraction or decimal component. It can be positive, negative, or zero. For example, -46, -1, 0, 5, and 3,278 are all integers, while -22.75, 3/4, √3, π, and 10.333 are not. The set of integers is infinite, extending in both the positive and negative directions.
In computer programming, an integer is a common data type used to store whole-number values. Integers may represent counters, quantities, scores, timestamps, and other values that do not require decimal places. They are often used as indexes that identify an element's position within an array or list, with 0 being the first value.
Computers typically store integers using a fixed number of bits, which limits the range of values they can represent. For example, a signed 32-bit integer typically ranges from -2,147,483,648 to 2,147,483,647. An unsigned integer does not represent negative values, allowing it to store a maximum value of 4,294,967,295.
Adding, subtracting, or multiplying two integers always produces another integer. Division may produce a fractional value, though the result depends on the programming language and data types involved. Some languages, like C++ and Java perform integer division by discarding the remainder, meaning 6 divided by 4 produces 1 instead of 1.5. A program may also round, truncate, or convert a decimal value when storing it as an integer.
Test Your Knowledge