string - C++: cannot initialize a variable of type 'char**' with a rvalue of type 'char*[x]' -


this question has answer here:

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 

demo.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -