How to Declare a 32-bit Integer in C How to Declare a 32-bit Integer in C c c

How to Declare a 32-bit Integer in C


#include <stdint.h>int32_t my_32bit_int;


C doesn't concern itself very much with exact sizes of integer types, C99 introduces the header stdint.h , which is probably your best bet. Include that and you can use e.g. int32_t. Of course not all platforms might support that.


Corey's answer is correct for "best", in my opinion, but a simple "int" will also work in practice (given that you're ignoring systems with 16-bit int). At this point, so much code depends on int being 32-bit that system vendors aren't going to change it.

(See also why long is 32-bit on lots of 64-bit systems and why we have "long long".)

One of the benefits of using int32_t, though, is that you're not perpetuating this problem!