C syntax, array value derefrencing?

I'm using an array to store some values that will be used in a sketch. This declaration is near the top of the sketch:

int outputs[OutputCount][3] = {{  5,  10,  13},  // Output A
                               { 15,  20,  12},  // Output B
                               {  2,  12,  11},  // Output C
                               { 10,   2,  10}}; // Output D

Later in the sketch in one of the functions I want to use one of the values:

void foo(){
  int i = *outputs[bar, baz];

The compiler wants me to include the asterisk:

error: invalid conversion from 'int*' to 'int'

However, if I reference the data thusly:

void foo(){
  int i = outputs[bar][baz];

the asterisk is not required.

Why is this?

The construct *outputs[bar, baz] is just not correct. You are actually (ab)using the C "comma operator", which is infrequently used. It works like this:i = 2, 3; // i will have the value 3 The comma operator discards its left-side operand and returns its right-side operand. You probably only see the comma operator in use in for-statements:for (i=0, j=0; i<10; i++, j++) ....So...back to your problem. By writing *outputs[bar, baz] you are writing the very same thing as *outputs[baz]which is only a single-dimensional array dereference, hence the '*' to fully dereference.

Ah, cool, thanks. I figured it would be something like that, but I wasn't aware of the comma operator. That will actually come in handy in a couple of places :slight_smile: