Question about pointers

I would like to give a name to different elements of a boolean array, like use Red for Array[1], Blue for Array[2], etc.
I test this using the following sketch but get errors when I try to Serial.print the values.

What is wrong?

sketch_apr29a.ino (228 Bytes)

Post the code.
Post the error messages.

Before you do anything else please take a moment to read General guidance and
How to use this forum
Especially item #7 on posting code.

Thank you.

OP's code:

bool Sw[5] = {true,false, false, true, true};
bool *Test0;
bool *Test1;


void setup() {
 
Test0 = &Sw[0];
Test1 = &Sw[1];


Serial.begin(9600);        
}

void loop() {
  
  Serial.print   (Test0);
  Serial.println (Test1);

}

Which uses pointers and doesn't realize you have to dereference them.

This is probably more elegantly done with an enumeration (enum) for the array index, or even #define

swdick:
I would like to give a name to different elements of a boolean array, like use Red for Array[1], Blue for Array[2], etc.

Maybe a simpler approach would be like this

byte Red = 1;
byte Blue = 2;

redVal = Array[Red];
blueVal = Array[Blue];

…R

As MarkT says...

Serial.print   (*Test0);
Serial.println (*Test1);

But better...

#define Test0 0
#define Test1 1


Serial.print   (Sw[Test0]);
Serial.println (Sw[Test1]);

This appears to do close to what you want. By using references (&) instead of pointer (*) the value doesn't have to be explicitly dereferenced.

bool Sw[5] = {true, false, false, true, true};
const bool &Test0 = Sw[0];
const bool &Test1 = Sw[1];


void setup()
{
  Serial.begin(9600);
}


void loop()
{
  Serial.print   (Test0);
  Serial.println (Test1);
}

Yes, this does the trick. Thanbks a lot.