1 Replies - 505 Views - Last Post: 03 December 2008 - 12:36 PM Rate Topic: -----

#1 ruby09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-December 08

an array question

Posted 03 December 2008 - 12:07 PM

>hi i am a begginer in c++ programming;
>i know that arrays cannot return values from a function, but structures can.
>if i wanted to return an array, how could i reformat my data to accomplish this?
>are there any drawbacks?
>thanx :)
Is This A Good Question/Topic? 0
  • +

Replies To: an array question

#2 GWatt   User is offline

  • member icon

Reputation: 312
  • View blog
  • Posts: 3,107
  • Joined: 01-December 05

Re: an array question

Posted 03 December 2008 - 12:36 PM

What you can do is pass the array as a an argument to the function. Because an array is a reference, the changes made to the array in the function will affect the array everywhere

    int array[10];
    function (array);
    //now array is filled with the numbers 0..9
}

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


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1