fork download
  1. //Adam Sanchez CIS5 Chapter 2, P. 82, #9
  2. /*******************************************************************************
  3.  *
  4.  * COMPUTE DATA TYPE SIZES
  5.  * _____________________________________________________________________________
  6.  * This program displays the number of bytes which are required to store the following
  7.  * data types:char, int, float, double.
  8.  * _____________________________________________________________________________
  9.  * Input
  10.  * The number of bytes associated with each data type.
  11.  *
  12.  * Output
  13.  * The number of byte(s) associated with each data type.
  14.  *
  15.  ******************************************************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. //
  22. // Compute Byte Sizes of Data Types and Output Results
  23. cout << "The byte size of a char is " << sizeof(char) << "." << endl;
  24. cout << "The byte size of int is " << sizeof(int) << "." << endl;
  25. cout << "The byte size of float is " << sizeof(float) << "." << endl;
  26. cout << "The byte size of double is " << sizeof(double) << "." << endl;
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
The byte size of a char is 1.
The byte size of int is 4.
The byte size of float is 4.
The byte size of double is 8.