+ 4

How can we access the elements in structure,where structure present in union?

20th Dec 2018, 6:25 PM
Lohith Viswa
Lohith Viswa - avatar
4 Antworten
+ 8
You either have to use an anonymous struct inside a union like so typedef union { struct { int a; double b; }; } un; and access the members of the struct as int main() { un x; x.a = 5; x.b = 1.5; } or create an object of a regular struct right after the struct definition inside the union like this typedef union { struct str { int a; double b; } s; } un; and access the members of the struct as int main() { un x; x.s.a = 5; x.s.b = 1.5; }
20th Dec 2018, 7:13 PM
Babak
Babak - avatar
+ 4
I want combination of structures and unions
20th Dec 2018, 6:38 PM
Lohith Viswa
Lohith Viswa - avatar
+ 3
by using the . dot operator between the variable name and the member name. https://www.sololearn.com/learn/C/2944/
20th Dec 2018, 6:32 PM
Gordon
Gordon - avatar
+ 3
Thanq
20th Dec 2018, 7:14 PM
Lohith Viswa
Lohith Viswa - avatar