C++ int type Signed Integer Types

Introduction

The following table lists the complete set of types that store signed integers.

The signed integers can have both positive and negative values.

Type Name
Typical Size (bytes)
Range of Values
signed char
1
-128 to 127
short
short int
2

-256 to 255

int
4
-2,147,483,648 to +2,147,483,647
long or long int
4
-2,147,483,648 to +2,147,483,647
long long or long long int
8
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Here are some examples of variables of some of these types:

#include <iostream>

int main() {//  w  w w . j a v  a2  s. c  om
    signed char ch {20};
    long temperature {-50L};
    long width {500L};
    long long height {250LL};
    unsigned int toe_count {10U};
    unsigned long angel_count {1000000UL};

  std::cout << "The value of char is "  << char  << std::endl;
  std::cout << "The value of temperature is " << temperature << std::endl;
  std::cout << "The value of height is "  << height  << std::endl;
}



PreviousNext

Related