由于每一台计算机都安装了一定数量的RAM,在系统中,通常用千兆字节(GB)表示RAM的数量(例如:1GB、2GB、4GB、8GB等)。计算机中的RAM是按照顺序逐字节排列的。内存中的每一个字节都要有一个可识别的唯一地址,用于区别内存中的不同字节,从零开始增长至内存的最大值。就现在而言,我们不用了解地址的细节,C编译器会自动处理地址的问题。
如果我们熟悉变量的类型、变量的定义、变量的赋值以及变量的运算,这样会加大我们程序的运行速度,在大型程序中,定义不同的变量在RAM运行中,会相差比较大的运算速度。例如,一个整形我们可以将他定义为int型变量,或者是double型变量,两者在RAM中占用的内存相差一倍;不仅如此,两者在计算机运行时,需要的时间相差比较大,虽然肉眼不能分别出来,但是我相信,在进行大量的数据运算时,会有分别。
/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
int main()
{
printf("\nA char is %d bytes",sizeof(char));
printf("\nA int is %d bytes",sizeof(int));
printf("\nA shart is %d bytes",sizeof(short));
printf("\nA long is %d bytes",sizeof(long));
printf("\nA long long is %d bytes",sizeof(long long));
printf("\nA unsigned char is %d bytes",sizeof(unsigned char));
printf("\nA unsigned int is %d bytes",sizeof(unsigned int));
printf("\nA unsigned short is %d bytes",sizeof(unsigned short));
printf("\nA unsigned long is %d bytes",sizeof(unsigned long));
printf("\nA unsigned long long is %d bytes",sizeof(unsigned long long));
printf("\nA float is %d bytes",sizeof(float));
printf("\nA double is %d bytes",sizeof(double));
printf("\nA long double is %d bytes",sizeof(long double));
printf("\n");
return 0;
}
{
printf("\nA char is %d bytes",sizeof(char));
printf("\nA int is %d bytes",sizeof(int));
printf("\nA shart is %d bytes",sizeof(short));
printf("\nA long is %d bytes",sizeof(long));
printf("\nA long long is %d bytes",sizeof(long long));
printf("\nA unsigned char is %d bytes",sizeof(unsigned char));
printf("\nA unsigned int is %d bytes",sizeof(unsigned int));
printf("\nA unsigned short is %d bytes",sizeof(unsigned short));
printf("\nA unsigned long is %d bytes",sizeof(unsigned long));
printf("\nA unsigned long long is %d bytes",sizeof(unsigned long long));
printf("\nA float is %d bytes",sizeof(float));
printf("\nA double is %d bytes",sizeof(double));
printf("\nA long double is %d bytes",sizeof(long double));
printf("\n");
return 0;
}
[root@localhost 1012]# ./demo
A char is 1 bytes
A int is 4 bytes
A shart is 2 bytes
A long is 4 bytes
A long long is 8 bytes
A unsigned char is 1 bytes
A unsigned int is 4 bytes
A unsigned short is 2 bytes
A unsigned long is 4 bytes
A unsigned long long is 8 bytes
A float is 4 bytes
A double is 8 bytes
A long double is 12 bytes
[root@localhost 1012]#
A int is 4 bytes
A shart is 2 bytes
A long is 4 bytes
A long long is 8 bytes
A unsigned char is 1 bytes
A unsigned int is 4 bytes
A unsigned short is 2 bytes
A unsigned long is 4 bytes
A unsigned long long is 8 bytes
A float is 4 bytes
A double is 8 bytes
A long double is 12 bytes
[root@localhost 1012]#