Home > Blockchain >  Successor of INT_MAX and INT_MIN
Successor of INT_MAX and INT_MIN

Time:10-30

I have 2 questions,

Is 1e9 less than INT_MAX value from the header file climits?

Is -1e9 greater than INT_MIN value from the header file climits?

and if I need to use in my program, some big positive number or smallest negative number, I use INT_MAX or INT_MIN in general

but when there's some constraints in some cases like no use of header files to write your program, in that situation, can I use 1e9 and -1e9 as largest number and smallest number?

CodePudding user response:

Is 1e9 less than INT_MAX value from the header file climits?

It can be. It isn't necessarily. It depends on the target system.

Is -1e9 greater than INT_MIN value from the header file climits?

Same as above.

Since int isn't guaranteed to be sufficient, you should use at least long type, or the more specific aliases from <cstdint> header which are at least 32 bits wide if you need numbers in the range of [-1e9,1e9].

CodePudding user response:

Use a long instead, then the answer to both questions you pose is yes.

Its minimum range prior to C 20 is -2147483647 to 2147483647 which is large enough. (Cf. an int which has a minimum range of -32767 to 32767.)

Out of interest, from C 20 onwards the minimum is -2147483648 and signed integral types become simpler to work with.

  • Related