Question: Here is my program : 

```
#include <cstring>
const int SIZE =10; 

int main() 
{ 
    char aName [SIZE]; // creates an array on the stack
    std::strcpy(aName, "Mary");
    return 0;
}

```

This program is obviously useless, I am just trying to understand the behavior of the strcpy function.

Here is it's signature : 
`char * strcpy ( char * destination, const char * source )`

so when I do :
`std::strcpy(aName, "Mary");`

I am passing by value the variable aName. I know that the aName (in the main) contains the address of the array. 
So is this assertion correct : strcpy creates a local variable called destination that has as value the address of the array aName that I have created on the stack in the main function?

I am asking this because it is very confusing to me. Whenever I have encountered addresses it usually was to point to a memory allocated on the **heap**...

Thanks!

Answer: 
Whenever you encounter addresses it doesn't mean it will always point to memory allocated to heap.

You can assign the address of a variable to a pointer like this

```
int a=5;
int *myPtr= &a;

```

Now, `myPtr` is a pointer of type integer which points to the memory of variable which is created on **stack** which is `a` have value 5.

So, whenever you create a pointer and assign the (address of) memory using `new` keyword, it will allocate the memory on **heap**. So, if I assign the value like this it will be on stack

```
int *myPtr= new int[5];

```
Maybe it would help to look at an example implementation of `strcpy()`:

```
char* strcpy(char* d, const char* s)
{
    char* tmp = d;

    while (*tmp++ = *s++)
        ;

    return d;
}

```

That's really all there is to it. Copy characters from the source to the destination until the source character is null (including the null). Return the pointer to the beginning of the destination. Done.

Pointers point to memory. It doesn't matter if that memory is "stack", "heap" or "static".