Last active
March 14, 2016 02:54
-
-
Save rangerz/0dd49ef21cd8a612bb3b to your computer and use it in GitHub Desktop.
[C++] build-in type size and range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<iomanip> | |
#include<string> | |
#include<limits> | |
using namespace std; | |
#define SIZEOF(x) cout << \ | |
setw(24) << #x << \ | |
setw(9) << sizeof(x) << \ | |
setw(21) << (numeric_limits<x>::max)() << \ | |
setw(21) << (numeric_limits<x>::min)() << endl | |
#define SERIES(x) cout << endl << \ | |
setw(24) << "[" #x "]" << endl; | |
int main() | |
{ | |
cout << \ | |
setw(24) << "type" << \ | |
setw(9) << "sizeof()" << \ | |
setw(21) << "max" << \ | |
setw(21) << "min" << endl; | |
cout << "Boolean type:" << endl; | |
SIZEOF(bool); | |
cout << endl << "Character types:" << endl; | |
SIZEOF(char); | |
SIZEOF(unsigned char); | |
SIZEOF(signed char); | |
SIZEOF(wchar_t); | |
SIZEOF(char16_t); | |
SIZEOF(char32_t); | |
cout << endl << "Integer types:" << endl; | |
SIZEOF(int); | |
SIZEOF(signed); | |
SIZEOF(unsigned); | |
SIZEOF(short); | |
SIZEOF(long); | |
SIZEOF(long long); | |
SERIES(short int); | |
SIZEOF(short); | |
SIZEOF(short int); | |
SIZEOF(signed short); | |
SIZEOF(signed short int); | |
SERIES(unsigned short int); | |
SIZEOF(unsigned short); | |
SIZEOF(unsigned short int); | |
SERIES(int); | |
SIZEOF(int); | |
SIZEOF(signed); | |
SIZEOF(signed int); | |
SERIES(unsigned int); | |
SIZEOF(unsigned); | |
SIZEOF(unsigned int); | |
SERIES(long int); | |
SIZEOF(long); | |
SIZEOF(long int); | |
SIZEOF(signed long); | |
SIZEOF(signed long int); | |
SERIES(long long int); | |
SIZEOF(long long); | |
SIZEOF(long long int); | |
SIZEOF(signed long long); | |
SIZEOF(signed long long int); | |
SERIES(unsigned long long int); | |
SIZEOF(unsigned long long); | |
SIZEOF(unsigned long long int); | |
cout << endl << "Floating point types:" << endl; | |
SIZEOF(float); | |
SIZEOF(double); | |
SIZEOF(long double); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment