How to use anonymous union in C

1 Answer

0 votes
#include <stdio.h>

struct Test
{
    union
    {
        char ch;
        int n;
    };
};
 
int main()
{
    struct Test t;
    
    t.n = 97;
 
    printf("t.ch = %c  t.n = %d\n", t.ch, t.n);
 
    return 0;
}


/*
run:

t.ch = a  t.n = 97

*/

 



answered Mar 17, 2018 by avibootz

Related questions

1 answer 176 views
176 views asked Dec 27, 2020 by avibootz
1 answer 200 views
1 answer 160 views
160 views asked Mar 17, 2018 by avibootz
1 answer 153 views
2 answers 166 views
1 answer 168 views
2 answers 242 views
242 views asked Aug 18, 2017 by avibootz
...