What is the proper method for modifying char array?

The other day I put together some code from the Unique ID library to modify a global chat array in my program. It works perfectly but going back I'm not sure if I understand why, can anyone help explain if I'm doing this the right way and if not what's the best way
Programming on a nano 33 iot with IDE 1.8
Here's my global variable

char SERIALNUMBER[33] = "FEDO198B50534D53302E3120FF160822";

Here's my function

void getSerialNumber(char num[33])
{
for (size_t i = 0; i < UniqueIDsize; i++)
  {
    if(((i*2)+1) > (sizeof(num) - 1)) break;

    char buf[3];

    if (UniqueID[i] < 0x10) num[i*2] = '0';

    sprintf(buf,"%X",UniqueID[i]);

    num[i*2] = buf[0];

    if(UniqueID[i] > 0x10) num[(i*2)+1] = buf[1];

  }
 debugPort->println(num);
}

And here's how I use it

 getSerialNumber(SERIALNUMBER);

The Result on the Serial port is this:
DEDE198B50534D53302E3120FF160822

So I do know that without passing SERIALNUMBER[x] and just passing SERIALNUMBER that I'm passing a pointer to the beginning of the char array. What I don't understand is how num[33] is modifying SERIALNUMBER[33]. My only guess is that I'm creating a new char array in the same space as SERIALNUMBER?
Another question is the fact that this is a char array effect it working, like could I modify any array in a similar fashion when the array sizes are identical inside and out of the function?

EDITED for readability

It's called "passing by reference". You can look that up and get a clearer more detailed answer than if someone here explains it. Essentially, it is creating an "alias" for the passed identifier.

Your second question is not that clear, but when using pass by reference, you could pass any array to it with the same results. If that answers it.

BTW you shouldn't really hard code the array size 33. It's probably UniqueIDsize + 1. Plus one is for the terminating null, just my guess.

I've changed the function declaration to this

void getSerialNumber(char num[(UniqueIDsize*2)+1]){ and the same for the global variable, that's a great idea so it works on any board. Second question was basically asking if this is like luck that it works this way because it's a char array will a null terminated character or if I used it with any array it would work the same. I'm going to look up passing by reference now

It's confusing, because although the array is null terminated, the code doesn't seem to pay any attention to that.

@winner10920 your code is indented oddly and seems to imply flow that is not what will happen.

Use the IDE auto format tool, then look at your code and see if you need to sprinkle some braces on in there. Or if you need(ed) to indent the way it changes to.

Just sayin’.

a7

What happens when UnidqueID[i] == 0x10? This code does not handle that case. Better to just let sprintf() handle it correctly

    sprintf(buf,"%02X",UniqueID[i]);
    num[i*2] = buf[0];
    num[i*2+1] = buf[1];