What happens when float pointer is typecasted to char pointer?

前端 未结 6 1404
后悔当初
后悔当初 2020-12-12 04:09
int main()
{
    float f = 12.2;
    char *p1;
    p1 = (char *)&f;
    printf (\"%d\", *p1);
}

This outputs 51.

6条回答
  •  执笔经年
    2020-12-12 04:54

    Mostly what EFraim says, except that you did cast to char*, only the stackoverflow markup was wrong.

    So you get the least significant byte of f's internal representation (in IEEE-754).

提交回复
热议问题