Question: I'm trying to make simple function to adding elements to my array but it doesnt work well. can you help me?

```

void insert(int &n, string name[]){
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>name[i];
    }
}

int main(){
    int n;
    string name[n];
    insert(n,name);
}

```

Answer: 
C++ arrays [] do not grow on run time, use std::vector instead.

Also, since you are reading an integer from cin, you should insert in the vector the same type, not a string.

```
std::vector<int> v;   // creates a vector 
v.push_back( 10 );    // include a number in a vector  

```

<https://godbolt.org/z/v4xG6WEo1>
You are declaring the size of your array "name[]" to be "n" but you are asking the value of "n" after you have allocated the memory for array already. Either ask for size before creating array or just use vector to have it resize during runtime.

If you want to use arrays then do this:

```
void insert(string name[]){
    for (int i = 0; i < name.size(); i++)
    {
        cin>>name[i];
    }
}
int main(){
  int n;
  cin >> n;
  string name[n];
  insert(name);
}

```

If you want your array size to change whenever you want basically use vectors:

```
void insert(int &n, vector<string> name){
    string tmp;
    for (int i = 0; i < n; i++)
    {
        cin>>tmp;
        name.push_back(tmp);
    }
}
int main(){
  int n = ???;
  vector<string> name;
  insert(n,name);
}

```

you will still have to give the value of "n" in vector example as well because you need the value of "n" to run the loop in "insert" function.