Inserting a defined variable into an array

arrays, c, embedded

Solution

What you can do is have `Var_2_insert` a pointer to the 3rd index in the array:

unsigned char insert_here[4]; // since it's updating it shouldn't be const
unsigned char *Var_2_insert = &(insert_here[3]);
//you just need to update the use of var_2_insert to dereference..
//  var_2_insert = 225 // <-- before
   *var_2_insert = 225 // <-- after

Problem

I dont know if this is possible, but help give suggestions. I have a variable`unsigned char Var_2_insert;` and I have an array `const unsigned char insert_here[4];`. This variable is initialized at run time say `var_2_insert = 225;`. The idea is that index 3 in the array should have the value of var_2_insert always. So I want to try something like ``` insert_here[4] = { 0x00, 0x02, 0x03, Var_2_insert}; ``` So that any time I try to read the array `insert here`, It will have the present value of var_2_insert. Now I know if I go like this: `#define Var_2_insert 225` This will go well, but since this variable has to be updated at runtime, I tried ``` #define _VAR Var_2_insert insert_here[4] = { 0x00, 0x02, 0x03, _VAR}; ``` But does not work. So how can i go about this? I hope my question is clear enough. Thanks.

Original source