How do I make an element of an array have the same dynamic value as another element? I need to translate something like:
value of array[2] = value pointed by array[4]
into code.
The only way I see to do it, is to use an array of pointers. Thus, changes to one position will affect a different position if both positions point to the same object.
Like so:
int* array[5];
array[2] = array[4] = malloc(sizeof(int));
*array[2] = 25;
// now, *array[4] will also be 25
[] has higher precedence than *.*(array[2] = array[4] = malloc(sizeof(int))) = 25 :)array, the third shows how the indirection works.
array[2]to always be the same as the value pointed to byarray[4], without having to updatearray[2]manually?