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

```
Function parameters are its local variables.

In this call

```
std::strcpy(aName, "Mary");

```

the two arrays (one that is created in main with the automatic storage duration and other is the string literal that has the static storage duration) are implicitly converted to pointers to their first elements. 

So you may imagine this call and the function definition the following way

```
std::strcpy(aName, "Mary");

 // …

char * strcpy ( /* char * destination, const char * source */ )
{
    char *destination = aName;
    const char *source = "Mary";

    // …

    return destination;
}

```

Or even like

```
char *p_to_aName = &aName[0];
const char *p_to_literal = &"Mary"[0];
std::strcpy( p_to_aName, p_to_literal );

 // …

char * strcpy ( /* char * destination, const char * source */ )
{
    char *destination = p_to_aName;
    const char *source = p_to_literal;

    // …

    return destination;
}

```

That is within the function its parameters are local variable of pointer types with the automatic storage duration that are initialized by pointers to first characters of the passed character arrays