Use sizeof operator to determine the sizes in bytes of the various data types on your computer system. - C++ Operator

C++ examples for Operator:sizeof

Description

Use sizeof operator to determine the sizes in bytes of the various data types on your computer system.

Demo Code

#include <fstream>
#include <iomanip>
#include <iostream>

int main(int argc, const char* argv[]) {
    std::fstream inOutFile("data-size.dat", std::ios::out);

    inOutFile << std::setw(20) << std::left << "char" << std::right
              << sizeof(char) << std::endl
              << std::setw(20) << std::left << "unsigned char" << std::right
              << sizeof(unsigned char) << std::endl
              << std::setw(20) << std::left << "short int" << sizeof(short int)
              << std::endl/*  ww  w .java 2 s  .c om*/
              << std::setw(20) << std::left << "unsigned short int"
              << sizeof(unsigned short int) << std::endl
              << std::setw(20) << std::left << "int" << sizeof(int) << std::endl
              << std::setw(20) << std::left << "unsigned int"
              << sizeof(unsigned int) << std::endl
              << std::setw(20) << std::left << "long int" << sizeof(long int)
              << std::endl
              << std::setw(20) << std::left << "unsigned long int"
              << sizeof(unsigned long int) << std::endl
              << std::setw(20) << std::left << "float" << sizeof(float)
              << std::endl
              << std::setw(20) << std::left << "double" << sizeof(double)
              << std::endl
              << std::setw(20) << std::left << "long double"
              << sizeof(long double) << std::endl;

    return 0;
}

Related Tutorials