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];

```
> 
> I know that the aName (in the main) contains the address of the array.
> 
> 
> 

You knew wrong. `aName` is an array. It contains the elements, not an address.

But when you use the name of the array as a value such as when passing it to strcpy, it is implicitly converted to a pointer to first element of the array (the value of a pointer is the memory address of the pointed object). Such implicit conversion is called *decaying*.

> 
> 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?
> 
> 
> 

This is correct enough. To clarify: It is a function argument rather than a local variable. But the distinction is not important here. Technically, it is the caller who is responsible for pushing the arguments onto the stack or storing them into registers, so it could be considered that `main` "creates" the variable.

> 
> Whenever I have encountered addresses it usually was to point to a memory allocated on the heap
> 
> 
> 

Pointers are not uniquely associated with "heap". Pretty much any object can be pointed at, whether it has dynamic, static or automatic storage or even if it is a subobject.