# changing arr[0] to arr[1]

• 09-01-2013
Darkroman
changing arr[0] to arr[1]
Here's what I mean

Code:

```void dectobin (int * arr, unsigned char b) {     arr[0] = (b & 128) ? 1 : 0;     if (b) dectobin (&arr[1], b << 1); }```
&arr[1] is what I'm mostly concerned about. I tested it out in some code:
Code:

```void testarray (int arr[]) {     arr[0] = 255; } // ... for (int i = 0; i < 8; ++i)     {         testarray(&testarr[1]);     } for (int i = 0; i < 8; ++i)     {         cout << "[" << i << "]: " << testarr[i] << endl;     }```
Indeed it did what I thought it would. Inside the function arr[0] is actually arr[1] because &testarr[1] makes arr[0] == arr[1]... wait, what?? Can someone explain to me the behind the scenes? The best explanation I have is &testarr[1] sets the address of arr[0] as arr[1]. My brain is stuck in an infinite loop of sorts. BTW, yes I know what the main code is, and fairly understand bitwise operations and truth tables.
• 09-01-2013
Salem
It doesn't make any difference to testarray, it's just a pointer to an int.
The fact that you made the parameter as int arr[] doesn't convey any extra arrayness properties.

You could do this.
Code:

```int array[10]; int val; int *p = malloc(10,sizeof(*p); // Then any of these testarray(array); testarray(&array[0]); testarray(&array[1]); testarray(&val); testarray(p); testarray(&p[0]); testarray(&p[1]);```
Just make sure the function in question doesn't try to access beyond the bounds of the supplied parameter.