Skip to content

Instantly share code, notes, and snippets.

@CorneliaXaos
Created April 11, 2017 07:17
Show Gist options
  • Save CorneliaXaos/d2a4f31dd4fb7473846bf431de524085 to your computer and use it in GitHub Desktop.
Save CorneliaXaos/d2a4f31dd4fb7473846bf431de524085 to your computer and use it in GitHub Desktop.
Prints out the bit width of all the fundamental numeric types in C++
#include <iostream>
#include <iomanip>
int main() {
std::cout << "Size of (in bits):" << std::endl <<
" bool: " << std::setw(2) << sizeof(bool) * 8 << " bits" << std::endl <<
" char: " << std::setw(2) << sizeof(char) * 8 << " bits" << std::endl <<
" char16_t: " << std::setw(2) << sizeof(char16_t) * 8 << " bits" << std::endl <<
" char32_t: " << std::setw(2) << sizeof(char32_t) * 8 << " bits" << std::endl <<
" wchar_t: " << std::setw(2) << sizeof(wchar_t) * 8 << " bits" << std::endl <<
" signed char: " << std::setw(2) << sizeof(signed char) * 8 << " bits" << std::endl <<
" short int: " << std::setw(2) << sizeof(short int) * 8 << " bits" << std::endl <<
" int: " << std::setw(2) << sizeof(int) * 8 << " bits" << std::endl <<
" long int: " << std::setw(2) << sizeof(long int) * 8 << " bits" << std::endl <<
" long long int: " << std::setw(2) << sizeof(long long int) * 8 << " bits" << std::endl <<
" unsigned char: " << std::setw(2) << sizeof(unsigned char) * 8 << " bits" << std::endl <<
" unsigned short int: " << std::setw(2) << sizeof(unsigned short int) * 8 << " bits" << std::endl <<
" unsigned int: " << std::setw(2) << sizeof(unsigned int) * 8 << " bits" << std::endl <<
" unsigned long int: " << std::setw(2) << sizeof(unsigned long int) * 8 << " bits" << std::endl <<
"unsigned long long int: " << std::setw(2) << sizeof(unsigned long long int) * 8 << " bits" << std::endl <<
" float: " << std::setw(2) << sizeof(float) * 8 << " bits" << std::endl <<
" double: " << std::setw(2) << sizeof(double) * 8 << " bits" << std::endl <<
" long double: " << std::setw(2) << sizeof(long double) * 8 << " bits" << std::endl;
}
@CorneliaXaos
Copy link
Author

Obviously this is architecture / cpu / compiler dependent.. different hardware will have different sizes for types.. but this can help you get some kind of idea as to the widths on any given platform. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment