Is there any macro in C or C++ represent the max and min value of int32_t and int64_t? I know it can be literally defined by oneself, but it's better if there is a standard macro. Please note I'm not asking about max of int, long ,etc. but intXX_t
Asked
Active
Viewed 5,441 times
6

xuhdev
- 8,018
- 2
- 41
- 69
-
2http://stackoverflow.com/questions/1855459/maximum-value-of-int – Colin Basnett Jul 28 '15 at 22:35
-
2`INTxx_MAX`, `INTxx_MIN` in `
` – BLUEPIXY Jul 28 '15 at 22:36 -
Beware about `__STDC_LIMIT_MACROS` and old C++ compilers – Ben Voigt Jul 28 '15 at 22:45
-
@BenVoigt: There is no such macro im C. – too honest for this site Jul 28 '15 at 22:46
-
@BenVoigt: Sorry, I did not get both expressions are related. Mostly, because there are actually `__STD_`-macros in C. – too honest for this site Jul 28 '15 at 22:50
-
1Reopened: the linked duplicate does not answer OP's question for C – M.M Jul 28 '15 at 23:18
2 Answers
14
In C++, there is std::numeric_limits::min()
and std::numeric_limits::max()
in the <limits>
header:
std::cout << std::numeric_limits<std::int32_t>::min() << std::endl;
and so on. In C, the header <stdint.h>
defines INT32_MIN
, INT32_MAX
etc. These are also available in the C++ <cstdint>
header.

juanchopanza
- 223,364
- 34
- 402
- 480
6
In C++ you can use header <limits>
and class std::numeric_limts
declared in this header.
To know the max and min values of types int32_t and int64_t you can write for example
#include <cstdint>
#include <limits>
//...
std::cout << std::numeric_limits<int32_t>::max() << std::endl;
std::cout << std::numeric_limits<int32_t>::min() << std::endl;
std::cout << std::numeric_limits<int64_t>::max() << std::endl;
std::cout << std::numeric_limits<int64_t>::min() << std::endl;
In C you should include header <stdint.h>
and use corresponding macros defined in the header as for example
INT32_MIN
INT32_MAX
INT64_MIN
INT64_MAX

Vlad from Moscow
- 301,070
- 26
- 186
- 335