Having this code:
#include <stdio.h>
#include <stdlib.h>
struct Test { char c; } foo;
int main (void) {
struct Test *ar[10];
struct Test *(*p)[10] = &ar; // var 'p' is kind of type "struct Test ***p"
*(*p+1) = malloc(sizeof(struct Test)*2); //alocated space in array p[0][1] for 2 structs
//Now I would like to have 'foo' from above in p[0][1][1]
// I cannot do "p[0][1][1] = foo", that is shallow copy
// which means "p[0][1][1].c = 'c'" will have no effect
// I need actually assign address to "&foo" to that pointer 'p'
// something like "(*(*p+1)+1) = &foo", but that is error:
//err: lvalue required as left operand of assignment
// reason:
p[0][1][1].c = 'c';
printf("%c\n", foo.c) // no output because foo is not in the array (its address was not assign to the pointer 'p')
return 0;
}
I would like to assign pointer struct Test ***p value of foo. So that I can manipulate with that pointer (declaring values in member of that struct). How to achieve this?
// var 'p' is kind of type "struct Test ***p"That's not true.[]and*are not freely interchangeable in all cases.pisstruct Test *(*)[10]. This is not the same asstruct Test ***, nor are the two types compatible. If you actually want a triple pointer (and, generally speaking, you shouldn't) then that's what you should declare.fooitself nor its address,&foo, has type compatible with either of the other two types mentioned. It's not clear what you hope to accomplish with all this, but you would be well advised to avoid playing games.