#include<stdio.h>
double i;
int main()
{
(int)(float)(char)开发者_开发技巧 i;
printf("%d", sizeof((int)(float)(char)i));
return 0;
}
The above outputs 4 on a Micrsoft compiler. Why?
sizeof
is the size, in bytes, of the variable. In this case, i
is being cast to an int
which is 4 bytes.
These are the sizes of types on MS C++: http://msdn.microsoft.com/en-us/library/cc953fe1(v=vs.71).aspx
The last cast operation is to int, so u will get the sizeOf(int). Integer size differes form compiler to another, some return 2-bytes and onther return 4-bytes.
sizeof
something tells you how many bytes it takes up in memory. Your platform and toolchain clearly has 32-bit integers; it's telling you that int
, on your toolchain (compiler), takes up 4 bytes.
精彩评论