title: Show byte representation of primitive values in C
body: <p>learning C and now i study simple code snipper that show byte representation of primitive values:</p>
  
  <pre><code>typedef unsigned char *byte_pointer;
  
  void show_bytes(byte_pointer start, int len) {
      int i;
      for (i = 0; i &lt; len; i++)
          printf(" %.2x", start[i]);
      printf("\n");
  }
  
  void show_float(float x) {
      show_bytes((byte_pointer) &amp;x, sizeof(float));
  }
  
  void show_int(int x) {
      show_bytes((byte_pointer) &amp;x, sizeof(int));
  }
  
  void show_pointer(void *x) {
      show_bytes((byte_pointer) &amp;x, sizeof(void *));
  }
  </code></pre>
  
  <p>If i understand correct, <code>&amp;x</code> (an ampersand character) showing address of memory (equal to <code>*x</code>).</p>
  
  <p>So. program routine is showing hexadecimal values of each data type, with <code>int</code> value of bytes like (<code>sizeof(int))</code>.</p>
  
  <p>Im not really understand how its work. First, we <code>typedef</code> pointer of unsigned char, and then use it with other types. What is the meaning of <code>(byte_pointer) &amp;x</code> and why does it work, when we define byte_pointer as value of type <code>unsigned char</code>? I understand that we get address of memory that contain value, but i don't know how exactly it work and WHY it work with char pointer. Could you explain that part?</p>
  
  <p>Thanks.</p>