STC89C51RC單片機數(shù)據(jù)類型的字節(jié)數(shù)測試
i = sizeof(char);//char是一字節(jié)的變量
if(i == 1)
{
led0 = 0;
}
i = sizeof(int);
if(i == 2)//led等亮,測試int是兩字節(jié)的變量
{
led1 = 0;
}
i = sizeof(unsigned int);//unsigned int 是兩字節(jié)的變量
if(i == 2)
{
led2 = 0;
}
i = sizeof(long);//long 是四字節(jié)的變量
if(i == 4)
{
led3 = 0;
}
i = sizeof(float);//float是四字節(jié)的變量
if(i == 4)
{
led4 = 0;
}
i = sizeof(double);//double是四字節(jié)的變量
if(i == 4)
{
led5 = 0;
}
int *pointer = 0;
int i =0;
i = sizeof(pointer);//指針的長度為3
if(4 == i)
{
led0 = 0;
}