Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to define anonymous struct inside anonymous union inside struct in C

1 Answer

0 votes
#include <stdio.h>

struct S 
{
   union { // anonymous union
      struct { int i, j; }; // anonymous structure
      struct { long x, y; } ist; // inner structure 
   };
   int n;
} s1;
 

int main(void)
{
    s1.i = 104;  
    printf("s1.i = %d\n", s1.i);
    
    //s1.x = 7;   // Error
    s1.ist.x = 13; 
    printf("s1.ist.x = %ld\n", s1.ist.x);
        
    printf("s1.i = %d\n", s1.i);
        
    return 0;
}

/*
run:
 
s1.i = 104
s1.ist.x = 13
s1.i = 13

*/

 



answered Aug 29, 2016 by avibootz

Related questions

1 answer 134 views
1 answer 147 views
147 views asked Dec 27, 2020 by avibootz
2 answers 133 views
2 answers 271 views
1 answer 200 views
1 answer 112 views
...