4

My system is Linux x86_64. The max value of int datatype (INT_MAX) is shown to be 2147483647 (using <limits.h> header) and not 32767 (as is the case for 16 bit int). Why?

RTh
  • 107
  • 1
  • 1
  • 4
  • 5
    Why not? Also isn't it 2147483647? – harold Feb 09 '15 at 16:34
  • C is pretty loose as to the definitions of the various integer types. Historically int could have been 16 or 32 bits (or some odd number, for that matter), and subsequent "standards" only tightened things up a little bit. If you want to write portable code you need to pay close attention to which data types you use. – Hot Licks Feb 09 '15 at 16:49
  • @HotLicks: Subsequent C standards haven't really "tightened things up". The minimum required range of `int` has remained at `-32767` .. `+32767` across C89/C90, C99, and C11. (POSIX requires at least 32-bit `int`.) – Keith Thompson Mar 07 '17 at 19:57
  • 1
    Possible duplicate of [What should be the sizeof(int) on a 64-bit machine?](https://stackoverflow.com/questions/10197242/what-should-be-the-sizeofint-on-a-64-bit-machine) – phuclv Jul 21 '18 at 06:16

6 Answers6

15

There is no type INT unless you define it yourself. The type is called int. C is case-sensitive.

The C standard says that an object of type int "has the natural size suggested by the architecture of the execution environment". For a 64-bit system, that does tend to imply that INT_MAX should be 263-1 -- but it's not a hard requirement.

The requirement is that int must be at least 16 bits wide, and that it must be at least as wide as short and no wider than long. (POSIX requires int to be at least 32 bits.)

It's useful to have integer types for all the sizes supported by the system. In particular, on most modern systems, it's useful to have predefined integer types of size 8, 16, 32, and 64 bits.

char is typically 8 bits. If we make int 64 bits, then either short is 16 bits and we have no 32-bit type, or short is 32 bits and we have no 16-bit type. (I've also worked on systems where there is no 16-bit or 32-bit integer type.)

A compiler could address this by defining its own extended integer types, but compilers typically don't do so.

In practice, making int 32 bits on 64-bit systems isn't a real problem. Operations on 32-bit integers are efficient, and if you want a 64-bit integer you can use long, long long, or int64_t, defined in <stdint.h>. (Actually 64-bit Windows defines long as 32 bits, but long long is always at least 64 bits.)

Bottom line: The C standard permits a fair amount of flexibility in how int is defined, and compiler implementers define it in the way they think will be most convenient to their users -- or, more commonly, in the way required by the platform's ABI. Compatibility with code written for 32-bit systems is often a major consideration.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • Note that for 64-bit 80x86; 32 bit is the default operand size in 64 bit code and almost every instruction that uses 64 bits requires an extra "REX prefix" byte, so a 64-bit `int` would be less efficient (for code size, instruction caches, etc) than a 32-bit `int`, and 32 bits is the natural size suggested by the architecture. – Brendan Apr 11 '20 at 01:47
7

The sizes of various integer types aren't guaranteed. The only thing you can count on is:

sizeof(long long) >= sizeof(long) >= sizeof(int) >= sizeof(short) >= sizeof(char) == 1

That said, in most real systems nowadays, you have:

sizeof(long long) == 8
sizeof(long)      == 8 or 4, depending on the architecture and compiler
sizeof(int)       == 4
sizeof(short)     == 2
sizeof(char)      == 1

int hasn't been 16bit in a long time. And it is very rarely 64bit. Usually long is the same size as the architecture, except on MSVC.

You can also get their min/max values using INT_MIN/INT_MAX and similar constants in limits.h

mtijanic
  • 2,872
  • 11
  • 26
  • 3
    I believe 64-bit Windows has `sizeof (long) == 4`. – Keith Thompson Feb 09 '15 at 16:43
  • 2
    Be very careful not to assume "sizeof" is "size of". I've seen platforms where "size of long" is 40 bits because it overflows at 2^39-1, but "sizeof(long)" is 8 bytes because "long" requires 64bit alignment. – user3528438 Feb 09 '15 at 18:07
  • Oh god, thank you so much for that. Stored away, so I don't spend countless hours debugging if it ever comes to that. Can you tell me which platform specifically? – mtijanic Feb 09 '15 at 18:43
6

I just compiled this program on my Linux Debian x64:

#include <stdio.h>

int main(){

// C18 standard, p. 20

    printf("\n\n***********************************************************************************\n\n");

    printf ("%-25s %20s %20s %15s\n\n", "", "IZVORNA KODA", "BINARNA KODA", "OPOMBA");

    signed char n009 = 255;
    printf ("%-25s %20s %20d %15s\n","signed char:", "255", n009, "!");

    signed char n007 = 128;
    printf ("%-25s %20s %20d %15s\n","signed char:", "128", n007, "!");

    signed char n006 = 127;
    printf ("%-25s %20s %20d %15s\n","signed char:", "127", n006, "MAX - C18");

    signed char n005 = 1;
    printf ("%-25s %20s %20d %15s\n","signed char:", "1", n005, "C18");

    signed char n004 = 0;
    printf ("%-25s %20s %20d %15s\n","signed char:", "0",  n004, "C18");

    signed char n003 = -1;
    printf ("%-25s %20s %20d %15s\n", "signed char:", "-1", n003, "C18");

    signed char n002 = -127;
    printf ("%-25s %20s %20d %15s\n", "signed char", "-127", n002, "C18");

    signed char n001 = -128;    
    printf ("%-25s %20s %20d %15s\n", "signed char", "-128", n001, "MIN - C18");

    printf("\nALOKACIJA: %d bitov",sizeof(n009)*8);

    printf("\n\n***********************************************************************************\n\n");

    printf ("%-25s %20s %20s %15s\n\n", "", "IZVORNA KODA", "BINARNA KODA", "OPOMBA");

    unsigned char n017 = 255;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "255", n017, "MAX - C18");

    unsigned char n016 = 128;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "128", n016, "C18");

    unsigned char n015 = 127;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "127", n015, "C18");

    unsigned char n014 = 1;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "1", n014, "C18");

    unsigned char n013 = 0;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "0", n013, "MIN - C18");

    unsigned char n012 = -1;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "-1", n012, "!");

    unsigned char n011 = -127;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "-127", n011, "!");

    unsigned char n010 = -128;
    printf ("%-25s %20s %20d %15s\n","unsigned char:", "-128", n010, "!");

    printf("\nALOKACIJA: %d bitov",sizeof(n010)*8);

    printf("\n\n***********************************************************************************\n\n");

    short int n018 = 65535;
    printf ("%-25s %20s %20d %15s\n","short int:", "65535", n018, "!");

    short int n019 = 32768;
    printf ("%-25s %20s %20d %15s\n","short int:", "32768", n019, "!");

    short int n020 = 32767;
    printf ("%-25s %20s %20d %15s\n","short int:", "32767", n020, "MAX - C18");

    short int n021 = 32766;
    printf ("%-25s %20s %20d %15s\n","short int:", "32766", n021, "C18");

    short int n022 = 1;
    printf ("%-25s %20s %20d %15s\n","short int:", "1", n022, "C18");

    short int n023 = 0;
    printf ("%-25s %20s %20d %15s\n","short int:", "0", n023, "C18");

    short int n024 = -1;
    printf ("%-25s %20s %20d %15s\n","short int:", "-1", n024, "C18");

    short int n025 = -32767;
    printf ("%-25s %20s %20d %15s\n","short int:", "-32767", n025, "C18");

    short int n026 = -32768;
    printf ("%-25s %20s %20d %15s\n","short int:", "-32768", n026, "MIN - C18");

    printf("\nALOKACIJA: %d bitov",sizeof(n026)*8);

    printf("\n\n***********************************************************************************\n\n");

    unsigned short int n027 = 65535;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "65535", n027, "MAX - C18");

    unsigned short int n028 = 32768;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "32768", n028, "C18");

    unsigned short int n029 = 32767;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "32767", n029, "C18");

    unsigned short int n030 = 32766;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "32766", n030, "C18");

    unsigned short int n031 = 1;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "1", n031, "C18");

    unsigned short int n032 = 0;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "0", n032, "MIN - C18");

    unsigned short int n033 = -1;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "-1", n033, "!");

    unsigned short int n034 = -32767;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "-32767", n034, "!");

    unsigned short int n035 = -32768;
    printf ("%-25s %20s %20d %15s\n","unsigned short int:", "-32768", n035, "!");

    printf("\nALOKACIJA: %d bitov",sizeof(n035)*8);

    printf("\n\n***********************************************************************************\n\n");

    int n036 = 4294967295;
    printf ("%-25s %20s %20d %15s\n","int:", "4294967295", n036, "!");

    int n037 = 2147483648;
    printf ("%-25s %20s %20d %15s\n","int:", "2147483648", n037, "!");

    int n038 = 2147483647;
    printf ("%-25s %20s %20d %15s\n","int:", "2147483647", n038, "MAX - C18");

    int n039 = 1;
    printf ("%-25s %20s %20d %15s\n","int:", "1", n039, "C18");

    int n040 = 0;
    printf ("%-25s %20s %20d %15s\n","int:", "0", n040, "C18");

    int n041 = -1;
    printf ("%-25s %20s %20d %15s\n","int:", "-1", n041, "C18");

    int n042 = -2147483647;
    printf ("%-25s %20s %20d %15s\n","int:", "-2147483647", n042, "C18");

    int nnnm = -2147483648;
    printf ("%-25s %20s %20d %15s\n","int:", "-2147483648", nnnm, "MIN - C18");

    printf("\nALOKACIJA: %d bitov",sizeof(n042)*8);

    printf("\n\n***********************************************************************************\n\n");

    unsigned int n043 = 4294967295;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "4294967295", n043, "!");

    unsigned int n044 = 4294967294;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "4294967294", n044, "!");

    unsigned int n045 = 2147483648;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "2147483648", n045, "!");

    unsigned int n046 = 2147483647;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "2147483647", n046, "MAX - C18");

    unsigned int n047 = 1;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "1", n047, "C18");

    unsigned int n048 = 0;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "0", n048, "MIN - C18");

    unsigned int n049 = -1;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "-1", n049, "?");

    unsigned int n05d = -2147483647;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "-2147483647", n05d, "?");

    unsigned int n050 = -2147483648;
    printf ("%-25s %20s %20d %15s\n","unsigned int:", "-2147483648", n050, "?");

    printf("\nALOKACIJA: %d bitov",sizeof(n050)*8);

    printf("\n\n***********************************************************************************\n\n");

    long int n051 = 9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","long int:", "9223372036854775807", n051, "!");

    long int n052 = 4294967294;
    printf ("%-25s %20s %20d %15s\n","long int:", "4294967294", n052, "!");

    long int n053 = 2147483648;
    printf ("%-25s %20s %20d %15s\n","long int:", "2147483648", n053, "!");

    long int n054 = 2147483647;
    printf ("%-25s %20s %20d %15s\n","long int:", "2147483647", n054, "MAX - C18");

    long int n055 = 1;
    printf ("%-25s %20s %20d %15s\n","long int:", "1", n055, "C18");

    long int n056 = 0;
    printf ("%-25s %20s %20d %15s\n","long int:", "0", n056, "C18");

    long int n057 = -1;
    printf ("%-25s %20s %20d %15s\n","long int:", "-1", n057, "C18");

    long int naaa = -2147483647;
    printf ("%-25s %20s %20d %15s\n","long int:", "-2147483647", naaa, "MIN - C18");

    long int n058 = -2147483648;
    printf ("%-25s %20s %20d %15s\n","long int:", "-2147483648", n058, "?");

    long int nnnn = -2147483649;
    printf ("%-25s %20s %20d %15s\n","long int:", "-2147483649", nnnn, "!");

    long int nbbb = -4294967294;
    printf ("%-25s %20s %20d %15s\n","long int:", "-4294967294", nbbb, "!");

    long int nccc = -9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","long int:", "-9223372036854775807", nccc, "!");

    printf("\nALOKACIJA: %d bitov",sizeof(n057)*8);


    printf("\n\n***********************************************************************************\n\n");

    unsigned long int n059 = 9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "9223372036854775807", n059, "!");

    unsigned long int n060 = 4294967294;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "4294967294", n060, "!");

    unsigned long int n061 = 2147483648;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "2147483648", n061, "!");

    unsigned long int n062 = 2147483647;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "2147483647", n062, "MAX - C18");

    unsigned long int n063 = 1;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "1", n063, "C18");

    unsigned long int n064 = 0;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "0", n064, "MIN - C18");

    unsigned long int n065 = -1;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "-1", n065, "?");

    unsigned long int n066 = -2147483648;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "-2147483648", n066, "?");

    unsigned long int nzzz = -4294967294;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "-4294967294", nzzz, "!");

    unsigned long int nggg = -9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","unsigned long int:", "-9223372036854775807", nggg, "!");

    printf("\nALOKACIJA: %d bitov",sizeof(n064)*8);

    printf("\n\n***********************************************************************************\n\n");

    long long int n080 = 9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","long long int:", "9223372036854775807", n080, "!");

    long long int n081 = 4294967294;
    printf ("%-25s %20s %20d %15s\n","long long int:", "4294967294", n081, "!");

    long long int n082 = 2147483648;
    printf ("%-25s %20s %20d %15s\n","long long int:", "2147483648", n082, "!");

    long long int n083 = 2147483647;
    printf ("%-25s %20s %20d %15s\n","long long int:", "2147483647", n083, "MAX - C18");

    long long int n084 = 1;
    printf ("%-25s %20s %20d %15s\n","long long int:", "1", n084, "C18");

    long long int n085 = 0;
    printf ("%-25s %20s %20d %15s\n","long long int:", "0", n085, "MIN - C18");

    long long int n086 = -1;
    printf ("%-25s %20s %20d %15s\n","long long int:", "-1", n086, "?");

    long long int n087 = -2147483648;
    printf ("%-25s %20s %20d %15s\n","long long int:", "-2147483648", n087, "?");

    long long int n088 = -4294967294;
    printf ("%-25s %20s %20d %15s\n","long long int:", "-4294967294", n088, "!");

    long long int n089 = -9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","long long int:", "-9223372036854775807", n089, "!");

    printf("\nALOKACIJA: %d bitov",sizeof(n089)*8);

    printf("\n\n***********************************************************************************\n\n");

    unsigned long long int n067 = 9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "9223372036854775807", n067, "!");

    unsigned long long int n068 = 4294967294;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "4294967294", n068, "!");

    unsigned long long int n069 = 2147483648;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "2147483648", n069, "!");

    unsigned long long int n070 = 2147483647;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "2147483647", n070, "MAX - C18");

    unsigned long long int n071 = 1;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "1", n071, "C18");

    unsigned long long int n072 = 0;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "0", n072, "MIN - C18");

    unsigned long long int n073 = -1;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "-1", n073, "?");

    unsigned long long int n074 = -2147483648;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "-2147483648", n074, "?");

    unsigned long long int n075 = -4294967294;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "-4294967294", n075, "!");

    unsigned long long int n076 = -9223372036854775807;
    printf ("%-25s %20s %20d %15s\n","unsigned long long int:", "-9223372036854775807", n076, "!");

    printf("\nALOKACIJA: %d bitov",sizeof(n076)*8);

    return 0;
}

I used a newest standard C18 to compile:

gcc -std=c18 -o 001 001.c

And as soon as I ran the binary, I got this output:

***********************************************************************************

                                  IZVORNA KODA         BINARNA KODA          OPOMBA

signed char:                               255                   -1               !
signed char:                               128                 -128               !
signed char:                               127                  127       MAX - C18
signed char:                                 1                    1             C18
signed char:                                 0                    0             C18
signed char:                                -1                   -1             C18
signed char                               -127                 -127             C18
signed char                               -128                 -128       MIN - C18

ALOKACIJA: 8 bitov

***********************************************************************************

                                  IZVORNA KODA         BINARNA KODA          OPOMBA

unsigned char:                             255                  255       MAX - C18
unsigned char:                             128                  128             C18
unsigned char:                             127                  127             C18
unsigned char:                               1                    1             C18
unsigned char:                               0                    0       MIN - C18
unsigned char:                              -1                  255               !
unsigned char:                            -127                  129               !
unsigned char:                            -128                  128               !

ALOKACIJA: 8 bitov

***********************************************************************************

short int:                               65535                   -1               !
short int:                               32768               -32768               !
short int:                               32767                32767       MAX - C18
short int:                               32766                32766             C18
short int:                                   1                    1             C18
short int:                                   0                    0             C18
short int:                                  -1                   -1             C18
short int:                              -32767               -32767             C18
short int:                              -32768               -32768       MIN - C18

ALOKACIJA: 16 bitov

***********************************************************************************

unsigned short int:                      65535                65535       MAX - C18
unsigned short int:                      32768                32768             C18
unsigned short int:                      32767                32767             C18
unsigned short int:                      32766                32766             C18
unsigned short int:                          1                    1             C18
unsigned short int:                          0                    0       MIN - C18
unsigned short int:                         -1                65535               !
unsigned short int:                     -32767                32769               !
unsigned short int:                     -32768                32768               !

ALOKACIJA: 16 bitov

***********************************************************************************

int:                                4294967295                   -1               !
int:                                2147483648          -2147483648               !
int:                                2147483647           2147483647       MAX - C18
int:                                         1                    1             C18
int:                                         0                    0             C18
int:                                        -1                   -1             C18
int:                               -2147483647          -2147483647             C18
int:                               -2147483648          -2147483648       MIN - C18

ALOKACIJA: 32 bitov

***********************************************************************************

unsigned int:                       4294967295                   -1               !
unsigned int:                       4294967294                   -2               !
unsigned int:                       2147483648          -2147483648               !
unsigned int:                       2147483647           2147483647       MAX - C18
unsigned int:                                1                    1             C18
unsigned int:                                0                    0       MIN - C18
unsigned int:                               -1                   -1               ?
unsigned int:                      -2147483647          -2147483647               ?
unsigned int:                      -2147483648          -2147483648               ?

ALOKACIJA: 32 bitov

***********************************************************************************

long int:                  9223372036854775807                   -1               !
long int:                           4294967294                   -2               !
long int:                           2147483648          -2147483648               !
long int:                           2147483647           2147483647       MAX - C18
long int:                                    1                    1             C18
long int:                                    0                    0             C18
long int:                                   -1                   -1             C18
long int:                          -2147483647          -2147483647       MIN - C18
long int:                          -2147483648          -2147483648               ?
long int:                          -2147483649           2147483647               !
long int:                          -4294967294                    2               !
long int:                 -9223372036854775807                    1               !

ALOKACIJA: 64 bitov

***********************************************************************************

unsigned long int:         9223372036854775807                   -1               !
unsigned long int:                  4294967294                   -2               !
unsigned long int:                  2147483648          -2147483648               !
unsigned long int:                  2147483647           2147483647       MAX - C18
unsigned long int:                           1                    1             C18
unsigned long int:                           0                    0       MIN - C18
unsigned long int:                          -1                   -1               ?
unsigned long int:                 -2147483648          -2147483648               ?
unsigned long int:                 -4294967294                    2               !
unsigned long int:        -9223372036854775807                    1               !

ALOKACIJA: 64 bitov

***********************************************************************************

long long int:             9223372036854775807                   -1               !
long long int:                      4294967294                   -2               !
long long int:                      2147483648          -2147483648               !
long long int:                      2147483647           2147483647       MAX - C18
long long int:                               1                    1             C18
long long int:                               0                    0       MIN - C18
long long int:                              -1                   -1               ?
long long int:                     -2147483648          -2147483648               ?
long long int:                     -4294967294                    2               !
long long int:            -9223372036854775807                    1               !

ALOKACIJA: 64 bitov

***********************************************************************************

unsigned long long int:    9223372036854775807                   -1               !
unsigned long long int:             4294967294                   -2               !
unsigned long long int:             2147483648          -2147483648               !
unsigned long long int:             2147483647           2147483647       MAX - C18
unsigned long long int:                      1                    1             C18
unsigned long long int:                      0                    0       MIN - C18
unsigned long long int:                     -1                   -1               ?
unsigned long long int:            -2147483648          -2147483648               ?
unsigned long long int:            -4294967294                    2               !
unsigned long long int:   -9223372036854775807                    1               !

where everything looks fine until unsigned int, long int,unsigned long int, long long int and unsigned long long int which are all the same and some even violate the standard (!) which clearly defines max and min values on page 20:

enter image description here

So it is clear that (a) there is a problem with the GCC toolchain and (b) you should avoid using int which is a disaster of the C programming language and this is why standard C11 presented the stdint.h which defines new integer data types:

  • int8_t
  • int16_t
  • int32_t
  • uint8_t
  • uint16_t
  • uint32_t
  • int64_t
  • uint64_t

and every single profesional programer out there is using the new data types, where old ones are kept for compatibility with older software but should be avoided.

Also pay attention to the online lessons. If they use old data types they clearly don't have a clue about C, so you should avoid those lessons.

71GA
  • 1,132
  • 6
  • 36
  • 69
0

Because 32 bit can represent integer value from 0 to 2147483647 and 16 bits can represent 0 to 32767.

It seems sizeof(int) = 4 bytes on your system so INT_MAX = 2147483647

PS: sizeof(int) varies from platform to platform.

chqrlie
  • 131,814
  • 10
  • 121
  • 189
Gopi
  • 19,784
  • 4
  • 24
  • 36
  • Assuming 2's-complement, a 32-bit `int` can represent values from `-2147483648` to `+2147483647`, and 32-bit `int` goes from `-32768` to `+32767`. Also, it's `INT_MAX`, not `MAX_INT`. – Keith Thompson Mar 07 '17 at 19:55
0

An int, as defined by the standard, has minimally 16 bits. 2^31 = 2147483648 (where the sign bit is left out), so you have an implementation that has a larger int than minimally required.

An int may even be a larger type, as the Standard only defines the minimal length and relative sizes to the other integral types.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
0

The minimum width for int is defined to be 16 bits by the standard, but that's not very common nowadays.

A 32-bit int, on the contrary, is common and your platform seems to have that as well, therefore your INT_MAX is probably 2147483647.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157