PDA

View Full Version : size of integer


pushparaj_bits
13th December 2011, 01:01 PM
In ANSI -C by Ritchie

It was defined as
int an integer, typically reflecting the natural size of integers on the host machine.

How to find the natural size of integers on the host machine.

markkuk
13th December 2011, 01:06 PM
printf("%d\n", sizeof(int));

Gareth Jones
13th December 2011, 05:18 PM

The "sizeof(type)" operator will give you the size of any C type (including structs), in terms of the number of bytes needed to store the type (excluding trailing alignment). If you need bits, multiply by the CHAR_BIT constant.

Gareth

Alberth5674764
15th December 2011, 08:17 PM
Note that different compilers may have different ideas about "natural size of integers", even at the same system.

If you want to be really sure of some size, K&R also defines a minimally required size (eg 'int' is at least 16 bit (iirc)).