int (C++)

int is the C++ type for whole numbers, such as 5, 0, or -42. It is the default choice for counting and integer arithmetic and is typically 32 bits wide.

C++

Because an int has a fixed size, it can overflow if a value grows beyond its range (commonly about 2.1 billion for a 32-bit int). For larger whole numbers, use long or long long.

Integer division in C++ discards the remainder: 7 / 2 gives 3, not 3.5.

Examples

C++

#include <iostream>

int main() {
    int a = 7;
    int b = 2;
    std::cout << a / b << std::endl;
    return 0;
}

Output:

3

Learn it in a lesson

See also

Back to the Dictionary