Integer data type in C++ programming language | Razsoft education

 Integer data type in C++

Integers are numbers with no fractional part. In C++ we represent integers in various type according to how big value they can store or what type of integer value they can store. All integer types has signed and unsigned type in C++.

  • Signed type integer can store both positive and negative integer values.
  • Unsigned type integer can store only positive values. 

In C++ there is four types of integers

  1. short,
  2. int,
  3. long, and
  4. long long (C++11).
  • C++ standard doesn't fixed size of any integer type so, it's on compiler developer and machine developer to define the size of integer types. So, it's size may differ from machine to machine or compiler to compiler.
  • C++ defines some rules how sizes of integers should be allocated. 
  • A short should be at least 16 bit big.
  • A long should be at least 32 bit big.
  • A long long should be at least 64 bit bog.
  • also, short <= int <= long <= long long.

climits header file

Because C++ doesn't fixed the size of integer data types so, every C++ compiler vender provide a header file called climits that contain the information about limit of every integer type in the header file. To know the limit we need to call for constant associated with every integer type. 


For example : 

        To know the maximum and minimum size of short integer we need to call for SHRT_MAX and SHRT_MIN respectively. 

  1. #include <iostream>
  2. #include <climits>
  3. using namespace std;
  4. int main(){
  5.       cout << " Maximum value of short integer is : " << SHRT_MAX  << endl;
  6.       cout << " Minimum value of short integer is : " << SHRT_MIN << endl;
  7. return 0;
  8. }
To learn more about climits header file click below.
There are following constants for short, int, long and long

short ->  SHRT_MIN, SHRT_MAX, USHRT_MAX.
int ->      INT_MIN, INT_MAX, UINT_MAX.
long -> LONG_MIN, LONG_MAX, ULONG_MAX.
long long -> LLONG_MIN, LLONG_MAX, ULLONG_MAX.

Minimum value of all integer types can store is 0.

  • char is also an integer data type but it has different purpose in programming we will not dicuss it here. Click below to read about it. 
  • char data type in C++ programming language 

Comments

Popular posts

"climits" Header file in c++ programming language | Razsoft Education

Computer graphics with java an introduction | Razsoft Education