473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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

Mar 5 '07 #1
0 1738

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Oplec | last post by:
Hi, I am learning standard C++ as a hobby. The C++ Programming Language : Special Edition has been the principal source for my information. I read the entirety of the book and concluded that I...
0
by: arnuld | last post by:
Stroustrup has a table in section 4.9 of declarations and definitions. he asks to write a similar table but in opposite sense: char ch; // declaration with definition he asks to do the...
4
by: arnuld | last post by:
here Stroustrup asks to write the smallest and largest values of char, int, short, long etc. i do not understand his question. when i will do sizeof(char), i wil only get one value in /byte/....
2
by: arnuld | last post by:
MAX and MIN values of CHAR could not be displayed. Why ? BTW, any advice on improvement ? (please remember i have covered chapter 4 only) ------------- PROGRAMME -------------- /*...
5
by: arnuld | last post by:
------------- PROGRAMME ----------- /* Stroustrup, 5.9, exercise 2 STATEMENT: what on your system, ar ethe restrictions on the types char*, int* and voic*? e.g. may an int* have an odd...
16
by: arnuld | last post by:
i did what i could do at Best to solve this exercise and this i what i have come up with: ----------- PROGRAMME -------------- /* Stroustrup 5.9, exercise 3 STATEMENT: Use typedef to define...
6
by: arnuld | last post by:
this one was much easier and works fine. as usual, i put code here for any further comments/views/advice: --------- PROGRAMME ------------ /* Stroustrup: 5.9 exercise 7 STATEMENTS: Define a...
14
by: arnuld | last post by:
there is no "compile-time error". after i enter input and hit ENTER i get a run-time error. here is the code: ---------- PROGRAMME -------------- /* Stroustrup, 5.9, exercise 11 STATEMENT:...
1
by: blangela | last post by:
Bjarne Stroustrup has a new text coming out called "Programming: Principles and Practice Using C++" (ISBN: 0321543726), due to be published in December of this year. Some of the features of this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.