一次使用多个联合体成员

#include stdio.hint main( void ){union flag {charc;inti;longl;floatf;double d;} shared;shared.c = $;

编程学习网为您整理以下代码实例,主要实现:一次使用多个联合体成员,希望可以帮到各位朋友。

#include <stdio.h>

int main( voID ){
    union flag {
        char   c;
        int    i;
        long   l;
        float  f;
        double d;
    } shared;

    shared.c = '$';

    printf("\nchar c   = %c",  shared.c);
    printf("\nint i    = %d",  shared.i);
    printf("\nlong l   = %ld", shared.l);
    printf("\nfloat f  = %f",  shared.f);
    printf("\ndouble d = %f",  shared.d);

    shared.d = 123456789.8765;

    printf("\n\nchar c   = %c",  shared.c);
    printf("\nint i    = %d",  shared.i);
    printf("\nlong l   = %ld", shared.l);
    printf("\nfloat f  = %f",  shared.f);
    printf("\ndouble d = %f\n",  shared.d);

    return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐