limits.cpp 1.0 KB

1234567891011121314151617181920212223242526272829
  1. // limits.cpp -- some integer limits
  2. #include <iostream>
  3. #include <climits> // use limits.h for older systems
  4. int main()
  5. {
  6. using namespace std;
  7. int n_int = INT_MAX; // initialize n_int to max int value
  8. short n_short = SHRT_MAX; // symbols defined in climits file
  9. long n_long = LONG_MAX;
  10. long long n_llong = LLONG_MAX;
  11. // sizeof operator yields size of type or of variable
  12. cout << "int is " << sizeof (int) << " bytes." << endl;
  13. cout << "short is " << sizeof n_short << " bytes." << endl;
  14. cout << "long is " << sizeof n_long << " bytes." << endl;
  15. cout << "long long is " << sizeof n_llong << " bytes." << endl;
  16. cout << endl;
  17. cout << "Maximum values:" << endl;
  18. cout << "int: " << n_int << endl;
  19. cout << "short: " << n_short << endl;
  20. cout << "long: " << n_long << endl;
  21. cout << "long long: " << n_llong << endl << endl;
  22. cout << "Minimum int value = " << INT_MIN << endl;
  23. cout << "Bits per byte = " << CHAR_BIT << endl;
  24. // cin.get();
  25. return 0;
  26. }