string - C++: cannot initialize a variable of type 'char**' with a rvalue of type 'char*[x]' -
this question has answer here:
- address of array 4 answers
char str_arr[] = "ads"; char *str_ptr = str_arr; char **ptr_str_ptr = &str_ptr; // ok char **ptr_str_arr = &str_arr; // compile error: cannot initialize variable of type 'char**' rvalue of type 'char*[4]'
i'm confused why cannot address of str_arr
. ideas?
you can address of str_arr
. however, address of array, not address of pointer. essentially, assignment fails because types not compatible.
here 1 illustration of why cannot assign pointer pointer char
, because possible:
char **ptr_str_arr = &str_arr; // imagine has worked *ptr_str_arr = new char[10]; // cannot done array
this not work const
pointers, either, because of type incompatibility.
char* const* ptr_const_str_arr = &str_arr; // not work either
Comments
Post a Comment