-4

char is 1 byte incremnt. int is 2 byte increment. float is 4 byte increment. double is 8 byte increment. why int increase 4 byte here?

Hex Increment Program

Hex Increment Output

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214

2 Answers2

3

Try this one:

int i;
...
printf("%d",sizeof(i));

What did you get? Most likely 4. Why? Because your CPU is most likely a 32bit one. The 2 byte int was true on older CPUs...

Never assume sizes of variables based on "should be", always use sizeof()!

ppeterka
  • 20,583
  • 6
  • 63
  • 78
0

int is 32 bits, so is float. Here, double is 64 bits.

On many 16-bit systems, int is 16 bits. C's int was intended to be whatever size is most natural for the system it is compiled for. There is no requirement that int be the same size across systems.

wallyk
  • 56,922
  • 16
  • 83
  • 148