I have a struct that stores 5 char * pointers
struct x {
char *arr[5];
};
I allocated memory for the struct using malloc()
struct x *str = malloc(sizeof(struct x));
However when i try to initialize arr with a value (namely a read only string-literal) it gives me an error
error: expected identifier before ‘(’ token
13 | (*str).(*(arr+0)) = "hello";
^
here is my initialization
(*str).(*(arr+0)) = "hello";
i know i could do it like this
str->arr[0] = "hello"
but i would like to understand how array of strings work, so i have used pointers and firstly dereferenced str-> and changed it to (*str).
Also since arr[0] works in the initialization str->arr[0] = "hello" and i know that arr[0] is equivalent to *(arr+i) where i is a array cell, i though that this would work in (*str).(*(arr+0)) = "hello"; but it does not.
Why is this and how are arrays of strings actually working behind the scenes?