title: Unexpected printf behaviour in c, printing float as hex changes value on each run
body: <p>I wrote some c code to play around with float values in memory, but ended up getting some unexpected output from printf compiling with &quot;gcc (GCC) 12.1.1 20220730&quot; with -std=c11 option.</p>
  <p><strong>I have no idea why it's behaving like this and would like to know what's happening, if I'm doing something wrong and how do I get it to printf a float value as hex if it's possible without converting it to another type first?</strong></p>
  <p>Here is the code used and output of different runs.</p>
  <p>Code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      float f3 = 1.1;
      float f4 = 1.0;
      unsigned char *t1 = &amp;f3;
  
      unsigned *t2 = &amp;f3;
  
      printf(&quot;P1: %x\n&quot;, t2[0]);
      printf(&quot;P2: %x %x %x %x\n&quot;, t1[0], t1[1], t1[2], t1[3]);
      printf(&quot;P3: %p\n&quot;, &amp;f3);
      printf(&quot;P4: %lx, %lx, %llx\n&quot;, &amp;f3, f3, f4);
  
      printf(&quot;T1: %f, %f, %lx, %lx\n&quot;, f3, f4, f4, f3);
      printf(&quot;T2: %x, %lx\n&quot;, f4, f3);
      printf(&quot;T3: %x, %lx\n&quot;, f3, f4);
      
      return 0;
  }
  </code></pre>
  <p>The main problem seems to be with printing a float as hex:</p>
  <pre><code>printf(&quot;%x\n&quot;, f3);
  </code></pre>
  <p>Output 1:</p>
  <pre class="lang-none prettyprint-override"><code>P1: 3f8ccccd                            // as expected
  P2: cd cc 8c 3f                         // as expected
  P3: 0x7ffc667d4d40                      // as expected
  P4: 7ffc667d4d40, 3ff19999a0000000, 0   // pointer value as expected, but second and third isn't. Values stay the same after each run
  
  T1: 1.100000, 1.000000, 5556db09b2a0, 0 // first two values as expected, second and third isn't, Values do not stay the same after each run
  T2: db09b2a0, 0                         // this value keeps changing after each run
  T3: db09b2a0, 0                         // same as above, but should be different? Also changes after each run.
  </code></pre>
  <p>Output 2:</p>
  <pre class="lang-none prettyprint-override"><code>P1: 3f8ccccd
  P2: cd cc 8c 3f
  P3: 0x7ffef87ebb00
  P4: 7ffef87ebb00, 3ff19999a0000000, 0
  
  T1: 1.100000, 1.000000, 55fb6a1962a0, 0
  T2: 6a1962a0, 0
  T3: 6a1962a0, 0
  </code></pre>
  <p>Output 3:</p>
  <pre class="lang-none prettyprint-override"><code>P1: 3f8ccccd
  P2: cd cc 8c 3f
  P3: 0x7ffdb2026640
  P4: 7ffdb2026640, 3ff19999a0000000, 0
  
  T1: 1.100000, 1.000000, 564dd210c2a0, 0
  T2: d210c2a0, 0
  T3: d210c2a0, 0
  </code></pre>