fork download
  1. //Adam Sanchez CIS5 Chapter 2, P. 82, #9
  2.  
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE DATA TYPE SIZES
  6.  * _____________________________________________________________________________
  7.  * This program computes byte sizes from these data types: char, int, float,
  8.  * and double.
  9.  * _____________________________________________________________________________
  10.  * Input
  11.  * char : a data type
  12.  * int : a data type
  13.  * float : a data type
  14.  * double : a data type
  15.  *
  16.  * Output
  17.  * byte size : amount of memory used by data type
  18.  *
  19.  ******************************************************************************/
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. //
  26. // Compute Byte Sizes of Data Types and Output Results
  27. cout << "The byte size of a char is " << sizeof(char) << "." << endl;
  28. cout << "The byte size of int is " << sizeof(int) << "." << endl;
  29. cout << "The byte size of float is " << sizeof(float) << "." << endl;
  30. cout << "The byte size of double is " << sizeof(double) << "." << endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 5324KB
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.