fork(1) download
  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.  
  21. cout << "long: " << n_long << endl;
  22. cout << "long long: " << n_llong << endl << endl;
  23. cout << "Minimum int value = " << INT_MIN << endl;
  24. cout << "Bits per byte = " << CHAR_BIT << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5512KB
stdin
Standard input is empty
stdout
int is 4 bytes.
short is 2 bytes.
long is 8 bytes.
long long is 8 bytes.

Maximum values:
int: 2147483647
short: 32767
long: 9223372036854775807
long long: 9223372036854775807

Minimum int value = -2147483648
Bits per byte = 8