Returning a char array from a function

Moderator:

  • I posted this in the wrong section.*
  • This should be in Programing questions.*
  • My apologies. *

So I figured out how to return a pointer to an array of characters.
It turns out that I can call it in either form.

// ASCII representation of hexadecimal digits.
const char DIGITS[] = "0123456789ABCDEF";

void setup ()
  { char tmp[]= "   "; 
    Serial.begin (9600);
      
    for (byte i=12; i<20; i++)
      { Serial.print(FormatByteAsHex (i, tmp));
          // output: "0C 0D 0E 0F 10 11 12 13"
      }
      Serial.println("");                         // output: "0C 0D 0E 0F 10 11 12 13"
      
    for (byte i=12; i<20; i++)
      { FormatByteAsHex (i, tmp);
        Serial.print ( tmp);
      }
      Serial.println("");                         // output: "0C 0D 0E 0F 10 11 12 13"
  }
 
void loop() {;} // do nothing

char *FormatByteAsHex(byte n, char tmp[])      
  { /* tmp[] must be at least two bytes */
    tmp[0] = DIGITS[(n >> 4) ];
    tmp[1] = DIGITS[n & 0xF];
    return tmp;
  }

The question is:
What happens to the pointer in the second form ?
Is the compiler smart enough to discard it or am I creating a memory leak?