【代码】我试了一下各种数据长度
#include <stdio.h> int main() { puts("各种数据类型所占内存字节数\n\n"); puts("integers:"); printf("sizeof(char) = %d\n",sizeof(char)); printf("sizeof(short int) = %d\n",sizeof(short)); printf("sizeof(int) = %d\n",sizeof(int)); printf("sizeof(unsigned int) = %d\n",sizeof(unsigned int)); printf("sizeof(long int) = %d\n",sizeof(long)); printf("sizeof(long long int) = %d\n",sizeof(long long )); puts("\nfloat:"); printf("sizeof(float) = %d\n",sizeof(float)); printf("sizeof(double) = %d\n",sizeof(double)); printf("sizeof(long double) = %d\n",sizeof(long double)); printf("\npointers:\n"); printf("sizeof(char *) = %d\n",sizeof(char *)); printf("sizeof(int *) = %d\n",sizeof(int *)); printf("sizeof(float *) = %d\n",sizeof(float *)); printf("sizeof(double *) = %d\n",sizeof(double *)); //64 bit system return 0; }
【结果】
各种数据类型所占内存字节数
integers:
sizeof(char) = 1
sizeof(short int) = 2
sizeof(int) = 4
sizeof(unsigned int) = 4
sizeof(long int) = 8
sizeof(long long int) = 8
float:
sizeof(float) = 4
sizeof(double) = 8
sizeof(long double) = 16
pointers:
sizeof(char *) = 8
sizeof(int *) = 8
sizeof(float *) = 8
sizeof(double *) = 8