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


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

Updated on: 23-Mar-2020

73 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements