Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Stroustrup Chapter 4, Exercise 3 - displaying the sizes of char, int etc.

Reply
Thread Tools

Stroustrup Chapter 4, Exercise 3 - displaying the sizes of char, int etc.

 
 
arnuld
Guest
Posts: n/a
 
      03-05-2007
this programme runs without any trouble. it took 45 minutes of typing.
i posted it here so that people can save their precious time:


// Stroustrup special edition
// chapter 4 exercise 2

// printing the sizes of different types


#include <iostream>

int main() {


bool b;

char c;
signed char sc;
unsigned char uc;
wchar_t wc;

int i;
unsigned int ui;
short s;
unsigned short us;
long l;
unsigned long ul;

float f;
double d;
long double ld;


bool* bp;

char* cp;
signed char* scp;
unsigned char* ucp;

int* ip;
unsigned int* uip;
short* sp;
unsigned short* usp;
long* lp;
unsigned long* ulp;

float* fp;
double* dp;
long double* ldp;

std::cout << "bool: \t" << sizeof(b)
<< "\n"

<< "char: \t" << sizeof(c) << "\n"
<< "signed char: \t" << sizeof(sc) << "\n"
<< "unsigned char: \t" << sizeof(uc) << "\n"
<< "wchar_t: \t" << sizeof(wc) << "\n"

<< "int: \t" << sizeof(i) << "\n"
<< "unsigned int: \t" << sizeof(ui) << "\n"
<< "short: \t" << sizeof(s) << "\n"
<< "unsigned short: \t" << sizeof(us) << "\n"
<< "long: \t" << sizeof(l) << "\n"
<< "unsigned long: \t" << sizeof(ul) << "\n"

<< "float: \t" << sizeof(f) << "\n"
<< "double: \t" << sizeof(d) << "\n"
<< "long double: \t" << sizeof(ld) << "\n"

<< "bool*: \t" << sizeof(bp) <<
"\n"
<< "char*: \t" << sizeof(cp) <<
"\n"
<< "unsigned char*: \t" << sizeof(ucp) <<
"\n"

<< "int*: \t" << sizeof(ip) << "\n"
<< "signed char*: \t" << sizeof(scp) << "\n"
<< "unsigned int*: \t" << sizeof(uip) << "\n"
<< "short*: \t" << sizeof(sp) << "\n"
<< "unsigned short*: \t" << sizeof(usp) << "\n"
<< "long*: \t" << sizeof(lp) << "\n"
<< "unsigned long*: \t" << sizeof(ulp) << "\n"

<< "float*: \t" << sizeof(fp) << "\n"
<< "double* \t" << sizeof(dp) << "\n"
<< "long double*: \t " << sizeof(ldp) << "\n"

<< "\n";
}

// created with Emacs, the true text editor

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stroustrup Chapter 4, Exercise 5 arnuld C++ 4 03-05-2007 04:05 PM
Stroustrup Chapter 4, Exercise 2 arnuld C++ 0 03-05-2007 02:34 PM
Stroustrup chapter 3 - 3.6 arnuld C++ 4 11-05-2006 11:25 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments