字(Word)是表示数据长度的单位。1字=2字节=16位
短整型(short)是一种整数数据类型,用于存储16位整数。
在C语言中,short范围为-2^(16-1)~2^(16-1)-1,即是-32768~+32767。
按符号位不同,short可分为unsigned short和signed(默认)short,其中,由于unsigned short符号位可用做存储数据,故其范围可以表示为0~2^16-1,即是0~65535
双字(Double Word)是表示数据长度的单位。1双字=4字节=32位。
(长long)整型(int)是一种整数数据类型,用于存储32位整数。
在C语言中,(long)int范围为-2^(32-1)~2^(32-1)-1,即是-2147483648~+2147483647。
按符号位不同,(long)int可分为unsigned (long)int和signed(默认)(long)int,其中,由于unsigned (long)int符号位可用做存储数据,故其范围可以表示为0~2^32-1,即是0~4294967295。
占用内存的情况。
#include <stdio.h>
#include "stm32f10x.h"
void printSizeOfIntType(void)
{
int sizeofInt = sizeof(int);
int sizeofShortInt = sizeof(short int);
int sizeofLongInt = sizeof(long int);
int sizeofUnsignedInt = sizeof(unsigned int);
int sizeofUnsignedShortInt = sizeof(unsigned short int);
int sizeofUnsignedLongInt = sizeof(unsigned long int);
printf("sizeof int is %d\n",sizeofInt);//sizeof int is 4
printf("sizeof short int is %d\n",sizeofShortInt);//sizeof short int is 2
printf("sizeof long int is %d\n",sizeofLongInt);//sizeof long int is 4
printf("sizeof unsigned int is %d\n",sizeofUnsignedInt);//sizeof unsigned int is 4
printf("sizeof unsigned short int is %d\n",sizeofUnsignedShortInt);//sizeof unsigned short int is 2
printf("sizeof unsigned long int is %d\n",sizeofUnsignedLongInt);//sizeof unsigned long int is 4
}
int main(void)
{
uint32_t syscount;
SystemInit();
printf("Hello World");
syscount = 0;
while (1)
{
printf("This is the %d times of the cricle",syscount);
printSizeOfIntType();
syscount++;
}
}