Test for “sizeof” operator

/*
  Name: Test for "sizeof" operator
  Copyright: no
  Author: David Vandevoorde's solution to "the C++ Programming Language"
  Typer:  Tom Gee
  Date: 01-03-03 22:00
  Description: this program shows how many bits the compiler allocates
               for each data type.
*/

#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;

struct Polymorph
{
    virtual ~Polymorph(){}
};

enum Bit{ Zero, One };
enum Intensity{ black = 0, brightness = 1000};

int main(int argc, char *argv[])
{
    //Integers
    cout<<"//Integers"<<endl;
    cout<<"sizeof(bool)="<<sizeof(bool)<<endl;
    cout<<"sizeof(char)="<<sizeof(char)<<endl;
    cout<<"sizeof(signed char)="<<sizeof(signed char)<<endl;
    cout<<"sizeof(unsigned char="<<sizeof(unsigned char)<<endl;
    cout<<"sizeof(wchar_t)="<<sizeof(wchar_t)<<endl;
    cout<<"sizeof(signed short=)"<<sizeof(signed short)<<endl;
    cout<<"sizeof(unsigned short)="<<sizeof(unsigned short)<<endl;
    cout<<"sizeof(signed int)="<<sizeof(signed int)<<endl;
    cout<<"sizeof(unsigned int)="<<sizeof(unsigned int)<<endl;
    cout<<"sizeof(signed long)="<<sizeof(signed long)<<endl;
    cout<<"sizeof(unsigned long)="<<sizeof(unsigned long)<<endl;
    #ifdef LONGLONG_EXT
    cout<<"sizeof(long long)="<<sizeof(long long)<<endl;
    #endif
    
    //floats
    cout<<"//floats"<<endl;    
    cout<<"sizeof(float)="<<sizeof(float)<<endl;
    cout<<"sizeof(double)="<<sizeof(double)<<endl;
    cout<<"sizeof(long double)="<<sizeof(long double)<<endl;
    
    //pointers
    cout<<"//poiters"<<endl;
    cout<<"sizeof(int *)="<<sizeof(int*)<<endl;
    cout<<"sizeof(int (*)())="<<sizeof(int(*)())<<endl;    
    cout<<"sizeof(void (Polymorph::*)())="<<sizeof(void (Polymorph::*)())<<endl; 
    cout<<"sizeof(void*)="<<sizeof(void*)<<endl;
    cout<<"sizeof(Bit)="<<sizeof(Bit)<<endl;
    cout<<"sizeof(Intensity)="<<sizeof(Intensity)<<endl;          
    
  system("PAUSE");	
  return 0;
}


Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: