title: Nested unions in c
body: <p>I don't understand why the output of following code is 15,15. unions are nested in the code. This question was asked in interview for a post of software engineer</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;malloc.h&gt;
  
  int main()
  {
      union A
      {
          long int y[5];
          union B
          {
              double g;
  
              union C
              {
                  int k;
  
                  union D
                  {
                      char ch;
                      int x[5];
                  }s;
              }a;
  
  
          }b;
  
      }*p;
  
      p = (union A*) malloc(sizeof(union A));
  
      p-&gt;b.a.k = 15;
  
      printf("%d ,%d", p-&gt;b.a.s.x[0], p-&gt;y[0] );
  
  
  }
  </code></pre>
  
  <p>This code prints 15,15. Please explain why this prints 15,15 and not garbage, garbage as i had expected? AND WHEN I USE float k instead of int k output is GARBAGE, GARBAGE why this is happening?</p>