quick question

Hi, I need short and clear answer :)

This code is for example:

int pins[6]= {2,3,4,5,6,7};               
int cols[3]= {pins[4],pins[5],pins[6]};         
int rows[3]= {pins[1],pins[2],pins[3]};

If i want to acces pin 2 on arduino, do I have to write rows[0] or rows[1]. I don't know if I have to begin with 0 or 1 when using this things.

Zero.

Thank you!

It would have been quicker to write a short sketch to try it out than to ask a question here - never mind waiting for the answer.

Where has personal initiative gone? Or the inquiring mind?

...R

ur000s:
Hi, I need short and clear answer :slight_smile:

This code is for example:

int pins[6]= {2,3,4,5,6,7};               

int cols[3]= {pins[4],pins[5],pins[6]};         
int rows[3]= {pins[1],pins[2],pins[3]};




If i want to acces pin 2 on arduino, do I have to write rows[0] or rows[1]. 
I don't know if I have to begin with 0 or 1 when using this things.

pins[6] is undefined, so the code is broken already. The pins array has
valid indexes from 0 to 5 inclusive.

ur000s: If i want to acces pin 2 on arduino, do I have to write rows[0] or rows[1].

Assuming that the numbers {2,3,4,5,6,7} refer to the actual Arduino pins, then Pin 2 is referenced by pins[0].

On the basis that you renumber you array indexes (from 1 -6 to 0-5) then rows[0] will be your answer.

Cheers

MarkT: The line:

int pins[6]= {2,3,4,5,6,7};

is not broken. When an integer constant appears in brackets as part of a data definition, it defines the number of elements to be allocated in memory by the compiler...it is not an index into the array.

What about this line though?

int cols[3]= {pins[4],pins[5],pins[6]};