Question: Hello I'm build a function are printing array with pointers
 on c with Visual Studio 2015.
while i run the function this send me this massage:
Run-Time Check Failure #2 - Stack around the variable 'arr' was corrupted.

this the function:

```
void arrprint(int* arr, int size)//printing numbers:
{

    size = (int)arr + size*sizeof(int);// the last adress of the array
    int* firstAdress = arr;
    for (arr=firstAdress; arr < size; arr++)
    {
        printf("%2d", *arr); //printing
    }
    *arr = firstAdress;  //for not destroy the array
    printf("\n");
}

```

thanks for helpers

Answer: 
This line

```
*arr = firstAdress;  //for not destroy the array

```

destroys the array. You are writing into the memory when you dereference `arr`.

---

Since in C, everything is passed by value, you do not have to worry about corruption when you change `arr` in the function. So, you do not need `firstAdress`.

```
void arrprint(int* arr, int size)//printing numbers:
{

    int* lastAddress = arr + size;
    int* firstAdress = arr;
    for (arr=firstAdress; arr < size; arr++)
    {
        printf("%2d", *arr); //printing
    }
    printf("\n");
}

```

After Updating, the code should look like this. You should notice that `arr` which is being changed here, is only being changed in this function, and the actual array pointer (in the caller function) is intact and safe.
Personally think the best solution is:

```
void arrprint(int* arr, int size)//printing numbers:
{
    int *lastAddress = arr + size    
    int *firstAddress = arr;
    for (firstAddress = arr; firstaddress < lastAddress; firstaddress++)
    {
        printf("%2d", *firstAddress); //printing
    }
    printf("\n");
}

```

Reason you do not alter the original pointer. You can also use const int\* arr in the function declaration, then you will get a compiler error if you dereference the pointer.