printf("sizeof(char) = %d\n", sizeof(char)); // 1 printf("sizeof(short) = %d\n", sizeof(short)); // 2 printf("sizeof(int) = %d\n", sizeof(int)); // 4 printf("sizeof(long) = %d\n", sizeof(long)); // 4 printf("sizeof(float) = %d\n", sizeof(float)); // 4 printf("sizeof(double) = %d\n", sizeof(double)); // 8 printf("sizeof(char) = %d\n", sizeof(char*)); // 4 printf("sizeof(short) = %d\n", sizeof(short*)); // 4 printf("sizeof(int) = %d\n", sizeof(int*)); // 4 printf("sizeof(long) = %d\n", sizeof(long*)); // 4 printf("sizeof(float) = %d\n", sizeof(float*)); // 4 printf("sizeof(double) = %d\n", sizeof(double*)); // 4Reason:
char
-128 ~ 127 -> 8 bits needed = 1 byte
unsigned char
0 ~255
short
-32768 ~ 32767 -> 16 bits needed = 2 bytes
unsigned short
0 ~ 65535
int
-2147483648 ~ 2147483647
float
32 bit (s + exp + fraction = 1 + 8 + 23)
double
64 bit (1 + 11 +52)
pointer
4 bytes = 1 word
Precision Problem
1. estimate the precision you want.
2. use big number.
float
32 bit (s + exp + fraction = 1 + 8 + 23)
double
64 bit (1 + 11 +52)
pointer
4 bytes = 1 word
Precision Problem
1. estimate the precision you want.
2. use big number.
沒有留言:
張貼留言