# question about returning pointer from a function (syntax)

Hi,

I hav a question about returning a pointer from a function. Are the following two function equivalent (the return statement is different)?

If they are how come they are the same?

``````uint8_t buff[16];

{
memset(buff, 0, sizeof(buff));

buff[0] = 'T';
buff[1] = 'C';
buff[2] = temp_c&0xff;
buff[3] = (temp_c>>8)&0xff;
buff[4] = (temp_c>>16)&0xff;
buff[5] = (temp_c>>24)&0xff;

return (&buff[0]);

}
``````
``````uint8_t buff[16];

{
memset(buff, 0, sizeof(buff));

buff[0] = 'T';
buff[1] = 'C';
buff[2] = temp_c&0xff;
buff[3] = (temp_c>>8)&0xff;
buff[4] = (temp_c>>16)&0xff;
buff[5] = (temp_c>>24)&0xff;

return (buff);

}
``````

I don't know if they are the same; the returned result is the same.

buff is an array; for arrays, it's the pointer to the first element.

buff[0] is the content of the first element; & takes the address of that element and hence &buff[0] points to the first element.

So in both cases, you return a pointer to the first element.

Yes they are the same thing

buff is already a pointer to the start of the array

Guix,

How is buff already a pointer to the start of the array? I thought it is just an array. Or this just the way c works?

Yes buff is equivalent to a pointer to an array.

``````int array [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
...
...
int x = array [1];
int y = *(array + 1);
int z = 1[array];
``````

Will result in x, y and z all being assigned the value 2.

Why do you need the function to return a pointer to a global variable? Whatever is calling the function will already have access to the global variable (array or not).