title: How to print integers and memory addresses to the console using write()?
body: <p>I am in a situation where I cannot use <code>printf()</code> to print to the console in C.
  It's a university assignment and we're reimplementing malloc, calloc, free and realloc. I am using ubuntu and when I call <code>printf()</code>, it seg faults as <code>printf()</code> uses malloc in its implementation (according to my lecturer), so I can't use it and have to use <code>write()</code> instead.</p>
  <p>So if I have a simple program, how can I print an integer and a pointer address to the console using <code>write()</code>.</p>
  <p>I have tried:</p>
  <pre><code>#include &lt;unistd.h&gt;
  
  int main(void) {
     int a = 12345;
     int* ptr = &amp;a;
     
     // none of the following seem to work
     write(2, &amp;a, sizeof(a));
     write(2, &quot;\n&quot;, 1);
     write(2, ptr, sizeof(ptr));
     write(2, &quot;\n&quot;, 1);
     write(2, &amp;ptr, sizeof(ptr));
     write(2, &quot;\n&quot;, 1);
  
     return 0;
  }
  </code></pre>
  <p>The output was</p>
  <pre><code>90
  90
  xZ???
  </code></pre>
  <p>Thanks, Juan</p>