指针的骚操作- 变量拼接和分离

/*此代码在 51单片机上验证通过,51为8位单片机,char占1个字节,long占四个字节*/
int main(void)
{
    unsigned long iii;
    unsigned char temp[4]={0xEC,0xEF,0x45,0x12};
    // 把四个 unsigned char 拼成一个 unsigned long.
    iii=*(unsigned long *)tempTime;
    SendString(string);
    // 把一个 unsigned long 分成四个 unsigned char.
    *(unsigned long *)tempTime = iii;
    SendString(tempTime);
    while(1);
}


unsigned int f_int[2];
float pi = 3.14;

*(float *)f_int = pi;
pi=*(float *)f_int;

 

 

posted @ 2019-04-06 10:49  路合华  阅读(325)  评论(0编辑  收藏  举报