title: Cast int to char array in C
body: <p>Is is possible to convert int to "string" in C just using casting? Without any functions like <code>atoi()</code> or <code>sprintf()</code>?</p>
  
  <p>What I want would be like this:</p>
  
  <pre><code>int main(int argc, char *argv[]) {
      int i = 500;
      char c[4];
  
      c = (char)i;
      i = 0;
      i = (int)c;
  }
  </code></pre>
  
  <p>The reason is that I need to generate two random ints (0 to 500) and send both as one string in a message queue to another process. The other process receives the message and do the LCM.</p>
  
  <p>I know how to do with <code>atoi()</code> and <code>itoa()</code>. But my teachers wants just using cast.</p>
  
  <p>Also, why isn't the following possible to compile?</p>
  
  <pre><code>typedef struct
  {
      int x;
      int y;
  } int_t;
  
  typedef struct
  {
      char x[sizeof(int)];
      char y[sizeof(int)];
  } char_t;
  
  int main(int argc, char *argv[])
  {
      int_t rand_int;
      char_t rand_char;
  
      rand_int.x = (rand() % 501);
      rand_int.y = (rand() % 501);
  
      rand_char = (char_t)rand_int;
  }
  </code></pre>