passing arrays by reference

I am new to Arduino, but come from a c++ back ground in microsofts VS. I am trying to pass an array into a function by reference, so that more than one function can operare on the same array. An example of what I'm trying to do:

void function(int &);

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

};

void loop(){
int counter[10];
function(&counter[]);
for(int i=0;i<10;i++){
Serial.println(counter*);*

  • }*
    };
    void function(int &functionary[]){
  • for(int i=0;i<10;i++){*
    funtionary_=(i10);_
    _
    }_
    _
    }_
    _
    [/quote]*_
    At least in VS. this is how I would do it, however arduino returns an error stating 'declaration of 'ary' as array of references'. I'm not really sure what to do as a work around. So far I have concluded that the prototype is needed to fix a bug in arduino's auto-prototyping, and I have found several postings saying you can not return an array from a function. Anything will help.
    rigg

Hi,

try this (pass pointer to int instead of reference):

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

void loop(){
  int counter[10];
  function(&counter[0]);
  for(int i=0;i<10;i++){
    Serial.println(counter[i]);
  }
};

void function(int* functionary){
  for(int i=0;i<10;i++){
    functionary[i] =(i*10);
  }
}

good luck
Mike