Retrieving values from Arrays

If I create an array in a function, I can do this:
int main();
{
int ConstantArray[3] = { 01, 02, 03};
cout << ConstantArray[1]
return 0;
}

and it should print "02" to the screen, right?

It seems that it is easy enough print the value within the same function but how do I get that info when I am trying to use it in a different function?

This is what I tried:
int GetValue();
{
cout << ConstantArray[1] << endl;
return 0;
}

Now how do I get the values from ConstantArray in the function GetValue?
I've read tutorials but the info is just not clicking.
Can anybody provide me with the piece of the puzzle I'm missing?
closed account (D80DSL3A)
You will need to pass the array to the function:
1
2
3
4
5
6
7
8
9
10
11
int getValue( int arr[] )
{
    cout << arr[1] << endl;
    return 0;// why?
}

int main()
{
    int ConstantArray[3] = { 01, 02, 03};
    getValue( ConstantArray );
}
Ok fun2code is also write that you should pass the array to getvalue function,...... its bit difficult concept if u r new to programming



Just make your array global
means declare it outside the main function.
Thank you! I made the array global and made the changes like fun2code had and it worked. Thanks so much for your help!

That had me stumped last night!!!
Topic archived. No new replies allowed.