Can I define pointer to a string array like this?
std::string* str_arr_p[];
Or I need to set the size of the array?
P.S.: Is there any difference between std::string* str_arr_p[n]; and std::string (*str_arr_p)[n];
Can I initialize pointer to a string array like this?
std::string* str_arr_p[];Or I need to set the size of the array?
No you can't. Try it and see that you get compilation error.
Is there any difference between
std::string* str_arr_p[n];andstd::string (*str_arr_p)[n];
Yes there is. The first is an array of n pointers to std::string, the second is a single pointer to an array of std::string of size n.
Note that both are uninitialized (if not declared as global or static), i.e. both point or hold arbitrary address(es). The first holds n arbitrary addresses that can be initialized separately with a valid address or nullptr for each of the n pointers in the array. The second is a single address that need to be initialized with an address of an std::string array which has the exact size n.
std::string ?"std::string* str_arr_p[n];
is an array of pointers to std::string.
std::string (*str_arr_p)[n]; here str_arr_p is a pointer to an array of n std::string
std::string* str_arr_p[]; this is a definition, you don't initialize anything.
std::string* str_arr_p[] = new std::string* [x]; heap allocated or
std::string* str_arr_p[50]; Stack allocated, this will be destroyed when function ends
std::vectorinstead.npointers tostd::string; the latter declares a pointer to an array ofnstd::string.