C 型態
C data types 分成整數(二補數), 浮點數(IEEE754)
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("char size=%ld\n",sizeof(char));
printf("signed char size=%ld\n",sizeof(signed char));
printf("unsigned char size=%ld\n",sizeof(unsigned char));
printf("short size=%ld\n",sizeof(short));
printf("short int size=%ld\n",sizeof(short int));
printf("signed short size=%ld\n",sizeof(signed short));
printf("signed short int size=%ld\n",sizeof(signed short int));
printf("unsigned short size=%ld\n",sizeof(unsigned short));
printf("unsigned short int size=%ld\n",sizeof(unsigned short int));
printf("int size=%ld\n",sizeof(int));
printf("signed int size=%ld\n",sizeof(signed int));
printf("unsigned size=%ld\n",sizeof(unsigned));
printf("unsigned int size=%ld\n",sizeof(unsigned int));
printf("long size=%ld\n",sizeof(long));
printf("long int size=%ld\n",sizeof(long int));
printf("signed long size=%ld\n",sizeof(signed long));
printf("signed long int size=%ld\n",sizeof(signed long int));
printf("unsigned long size=%ld\n",sizeof(unsigned long));
printf("unsigned long int size=%ld\n",sizeof(unsigned long int));
printf("long long size=%ld\n",sizeof(long long));
printf("long long int size=%ld\n",sizeof(long long int));
printf("signed long long size=%ld\n",sizeof(signed long long));
printf("signed long long int size=%ld\n",sizeof(signed long long int));
printf("unsigned long long size=%ld\n",sizeof(unsigned long long));
printf("unsigned long long int size=%ld\n",sizeof(unsigned long long int));
printf("float size=%ld\n",sizeof(float));
printf("double size=%ld\n",sizeof(double));
printf("long double size=%ld\n",sizeof(long double));
// 32bit CPU 指標佔4byte , 64bit CPU 佔 8byte
printf("\n\n\n\nchar* size=%ld\n",sizeof(char*));
printf("signed char* size=%ld\n",sizeof(signed char*));
printf("unsigned char* size=%ld\n",sizeof(unsigned char*));
printf("short* size=%ld\n",sizeof(short*));
printf("short int* size=%ld\n",sizeof(short int*));
printf("signed short* size=%ld\n",sizeof(signed short*));
printf("signed short int* size=%ld\n",sizeof(signed short int*));
printf("unsigned short* size=%ld\n",sizeof(unsigned short*));
printf("unsigned short int* size=%ld\n",sizeof(unsigned short int*));
printf("int* size=%ld\n",sizeof(int*));
printf("signed int* size=%ld\n",sizeof(signed int*));
printf("unsigned* size=%ld\n",sizeof(unsigned*));
printf("unsigned int* size=%ld\n",sizeof(unsigned int*));
printf("long* size=%ld\n",sizeof(long*));
printf("long int* size=%ld\n",sizeof(long int*));
printf("signed long* size=%ld\n",sizeof(signed long*));
printf("signed long int* size=%ld\n",sizeof(signed long int*));
printf("unsigned long* size=%ld\n",sizeof(unsigned long*));
printf("unsigned long int* size=%ld\n",sizeof(unsigned long int*));
printf("long long* size=%ld\n",sizeof(long long*));
printf("long long int* size=%ld\n",sizeof(long long int*));
printf("signed long long* size=%ld\n",sizeof(signed long long*));
printf("signed long long* int size=%ld\n",sizeof(signed long long int*));
printf("unsigned long long* size=%ld\n",sizeof(unsigned long long*));
printf("unsigned long long int* size=%ld\n",sizeof(unsigned long long int*));
printf("float* size=%ld\n",sizeof(float*));
printf("double* size=%ld\n",sizeof(double*));
printf("long double* size=%ld\n",sizeof(long double*));
printf("void* size=%ld\n",sizeof(void*));
return 0;
}
C data types
Type |
Explanation |
Format Specifier |
char |
Smallest addressable unit of the machine that can contain basic character set. It is an integer type. Actual type can be either signed or unsigned depending on the implementation. |
%c |
signed char |
Of the same size as char , but guaranteed to be signed. |
%c (or %hhi for numerical output) |
unsigned char |
Of the same size as char , but guaranteed to be unsigned. |
%c (or %hhu for numerical output) |
short
short int
signed short
signed short int |
Short signed integer type. Capable of containing at least the [−32767,+32767] range;[3] thus, it is at least 16 bits in size. |
%hi |
unsigned short
unsigned short int |
The same as short , but unsigned. |
%hu |
int
signed int |
Basic signed integer type. Capable of containing at least the [−32767,+32767] range;[3] thus, it is at least 16 bits in size. |
%i or %d |
unsigned
unsigned int |
The same as int , but unsigned. |
%u |
long
long int
signed long
signed long int |
Long signed integer type. Capable of containing at least the [−2147483647,+2147483647] range;[3] thus, it is at least 32 bits in size. |
%li |
unsigned long
unsigned long int |
The same as long , but unsigned. |
%lu |
long long
long long int
signed long long
signed long long int |
Long long signed integer type. Capable of containing at least the [−9223372036854775807,+9223372036854775807] range;[3] thus, it is at least 64 bits in size. Specified since the C99 version of the standard. |
%lli |
unsigned long long
unsigned long long int |
The same as long long , but unsigned. Specified since the C99 version of the standard. |
%llu |
float |
Real floating-point type, usually referred to as a single-precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the IEEE 754 single-precision binary floating-point format. This format is required by the optional Annex F "IEC 60559 floating-point arithmetic". |
%f (promoted automatically to double for printf() ) |
double |
Real floating-point type, usually referred to as a double-precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the IEEE 754 double-precision binary floating-point format. This format is required by the optional Annex F "IEC 60559 floating-point arithmetic". |
%f (%lf for scanf() ) |
long double |
Real floating-point type, usually mapped to an extended precision floating-point number format. Actual properties unspecified. Unlike types float and double , it can be either 80-bit floating point format, the non-IEEE "double-double" or IEEE 754 quadruple-precision floating-point format if a higher precision format is provided, otherwise it is the same as double . See the article on long double for details. |
%Lf |