Declaring and using array of structures in Arduino Printing structure variables, I get default values. What is wrong with my code?

struct SCENARIO
{
  int Lamp_Pin = -1;
  int PB_Pin = -1;
} ;

SCENARIO  _red;
SCENARIO  _yellow;
SCENARIO  _white;
SCENARIO  _stop;
SCENARIO btns[4] = { _red,  _yellow, _white, _stop};


void setup()
{ 
  _stop.Lamp_Pin = 8;
  _stop.PB_Pin = 4;

 ///// initializing other 3 objects i.e. red &amp; white &amp; yellow
 //// 
for (int i = 0; i &lt; 4; i++)
  {
    Serial.print(i);Serial.print(":");
    Serial.print(btns[i].Lamp_Pin);Serial.print(":");
    Serial.println( btns[i].PB_Pin );
    //pinMode(  btns[i].Lamp_Pin, OUTPUT);
    //pinMode(  btns[i].PB_Pin, INPUT);
  }
}


The image below shows what I get. It seems I have not initialized the variables!
The problem is that a struct is handled as a value type, not as a reference type.

This means that a copy of _stop is made and put in btns (btns[3] actually).

So what you need to do is putting pointers into the btns array:

SCENARIO* btns[4] = { &amp;_red, &amp;_yellow, &amp;_white, &amp;_stop};


The symbol * denotes a pointer, and &amp; means the address of a variable (so it points to the variable and is not a copy).

Now when you change _stop, also btns[3] which points to _stop will show the correct initialized value.

For printing you should use:

Serial.println( (*btns[i]).LampPin);Serial.print(":");
Serial.println( (*btns[i]).PB_Pin );


Because *btns[i] is a pointer, but because this is a very often used feature, a special notation can be used:

Serial.print(btns[i]-&gt;Lamp_Pin);Serial.print(":");
Serial.println( btns[i]-&gt;PB_Pin);