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.
You're trying to use `size` as an `int *`. Use an actual `int *` instead.

Also, by setting `*arr = firstAddress`, what you're really doing is writing the address of the array into the first *element* in the array. Also, since `arr` is a local variable, changes to it don't affect the variable in the calling function.

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

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

```