Extended Integral Types (Choosing the correct integer size in C/C++)

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to understand extended integral types in C/C++.

The data types in C are very loosely defined. Their range values changes on the basis of the compiler being 32 or 64 bit. To specify the compiler range you want to use in your program we use intN_t.

Example

 Live Demo

#include <iostream>
using namespace std;
int main(){
   uint8_t i; //mentioning the bit to be 8
   i = 0;
   cout << "Minimum value of i\t: "<<< (int)i << endl;
   i = 255;
   cout << "Maximum value of i\t: "<< (int)i << endl;
   //moving beyond the given bit will result in garbage value
   i = 2436;
   cout << "Beyond range value of i\t: " << (int)i << endl;
   return 0;
}

Output

Minimum value of i : 0
Maximum value of i : 255
Beyond range value of i : 132
raja
Published on 23-Mar-2020 08:36:44
Advertisements