2-3資料型態( Data Types) 整數型態( int type) °浮點數型態( floating-point type) 單精確度浮點數型態( float type) 倍精確度浮點數型態( double type) 字元型態( char type) 36
36 • 整數型態(int type) • 浮點數型態(floating-point type) – 單精確度浮點數型態(float type) – 倍精確度浮點數型態(double type) • 字元型態(char type) 2-3 資料型態(Data Types)
2-3-1整數型態( Int type) 整數型態 佔記憶體 數值範圍 容量 整數 int 4 bytes 2,147,483,648-2,147,483,647 含正負號整數 signed int 4 bytes -2,147,483648-2,147,483,647 無正負號整數 unsigned int4 bytes 0~4,294,967,295 短整數 shor七int 2 bytes -32.768~32.767 含正負號短整數 signed short in七 2 bytes 32,768~32,767 無正負號短整數 unsigned short 2 bytes 0~65.535 in七 長整數 long int 4 bytes -2,147,483,648~2,147,483647 含正負號長整數 signed long 4 bytes -2.147483.648~2,147483.647 in七 無正負號長整數 unsigned long 4 bytes 0~4,294967,295 in七
37 整數型態 佔記憶體 容量 數值範圍 整數 int 4 bytes -2,147,483,648~2,147,483,647 含正負號整數 signed int 4 bytes -2,147,483,648~2,147,483,647 無正負號整數 unsigned int 4 bytes 0~4,294,967,295 短整數 short int 2 bytes -32,768~32,767 含正負號短整數 signed short int 2 bytes -32,768~32,767 無正負號短整數 unsigned short int 2 bytes 0~65,535 長整數 long int 4 bytes -2,147,483,648~2,147,483,647 含正負號長整數 signed long int 4 bytes -2,147,483,648~2,147,483,647 無正負號長整數 unsigned long int 4 bytes 0~4,294,967,295 2-3-1 整數型態(int type)
Ch2 9 sizeof Ch2_9整數型態一計算所估的記憶體空間 佔多少 位元 #includestdio. h main printf( "The size of int is %1 bytes n", sizeof(int) printf(" The size of short int is %i bytes. nf, sizeof( short int) printf("The size of long int is %i bytes n sizeof(long int)s The size of int is 2 bytes The size of short int is 2 bytes The size of long int is 4 bytes 38
38 Ch2_9 sizeof() The size of int is 2 bytes. The size of short int is 2 bytes. The size of long int is 4 bytes. Ch2_9 整數型態─計算所佔的記憶體空間 #include<stdio.h> main(){ printf("The size of int is %i bytes.\n", sizeof(int)); printf("The size of short int is %i bytes.\n", sizeof(short int)); printf("The size of long int is %i bytes.\n", sizeof(long int)); } 佔多少 位元
2-3-2浮點數型態( floating- point type) 佔記憶體 有效位數 整數型態 數值範圍 容量 (小數點後) 實數 3.4E-38 float 4 bytes ~3.4E+38 長倍實數 1.7E-308 8 bytes 15 long float ~1.7E+308 雙倍實數 1.7E-308 double 8 bytes 15 1.7E+308 長雙倍實數 3.4E-4932 18 long double 10 bytes 1.1E+4932 39
39 整數型態 佔記憶體 容量 數值範圍 有效位數 (小數點後) 實數 float 4 bytes 3.4E-38 ~3.4E+38 7 長倍實數 long float 8 bytes 1.7E-308 ~1.7E+308 15 雙倍實數 double 8 bytes 1.7E-308 ~1.7E+308 15 長雙倍實數 long double 10 bytes 3.4E-4932 ~1.1E+4932 18 2-3-2 浮點數型態(floating-point type)
Ch210 Ch210浮點數型態一計算所佔的記憶體空周/佔多少 1 #include<stdio.h> 位元 ma 3 printf("The size of float is %l bytes. n'y sizeof( float)) 4 printf(" The size of double is %1 bytes In sizeof(double));/ 5 printf("The size of long double is %i bytes.\n sizeof(lo ong double)) The size of float is 4 bytes The size of double is 8 bytes The size of long double is 10 bytes 40
40 Ch2_10 The size of float is 4 bytes. The size of double is 8 bytes. The size of long double is 10 bytes. Ch2_10 浮點數型態─計算所佔的記憶體空間 1 #include<stdio.h> 2 main() { 3 printf("The size of float is %i bytes.\n", sizeof(float)); 4 printf("The size of double is %i bytes.\n", sizeof(double)); 5 printf("The size of long double is %i bytes.\n", sizeof(long double)); 6 } 佔多少 位元