解释此代码段? [英] Explain this code snippet?

查看:89
本文介绍了解释此代码段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释该程序如何工作

Can anyone explain how the program works

#include<stdio.h>
#include<math.h>
int main()
{
    float a=5.375;
    char *p;
    int i;
    p = (char*)&a;
    for(i=0; i<=3; i++)
        printf("%02x\n", (unsigned char)p[i]);
    return 0;
}


问候

推荐答案

float有四个字节,而char是一个字节(通常在32位系统上),程序只是加载(第一个字节)指向字符指针p,然后遍历字节并以十六进制打印值.
float has four bytes and char is one byte (usually, on 32 bit systems), the program is simply loading the address of a (the first byte) to character pointer p, then running though the bytes and printing the value in hex.


这篇关于解释此代码段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆