union

why does union a z2 = {0, 2}; give error ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<stdio.h>

int main()
{
    union a
    {
        int i;
        char ch[2];
    };
    union a z1 = {512};
    union a z2 = {0, 2};
    return 0;
}
dot operator should be used to initialise z2,that is, a.ch[0]=0 and a.ch[1]=2
Topic archived. No new replies allowed.