could any array passed by value???

We know that arrays are passed by reference. Do you know some way around to pass them by value........if not then why not???????
Please just put all your homework questions in one post.
First: Why would you want to? You could declare it const if you didn't want it to change anything.

An array is similar to (but not exactly the same as) a pointer to the first value of that array. You are effectively passing a pointer to a memory location.
dear Moschops i do :)
You can pass arrays by reference and by value. You can look in your book in the array chapter and it should explain it.

The two functions I found are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

//Pass by reference

modifyArray(a, arraySize);

//Function for passing by reference

void modifyArray(int b[], int sizeOfArray)
{
    for (int k = 0; k < sizeofArray; ++k)
    b[k] *= 2;
}

//Function modifyElement( int e)
{
    cout << "Value of element in modifyElement: "<< (e *= 2) endl;
}


//pass by value
modifyElement (a[3]);


This should give you a headstart.
It is not possible to pass C arrays by value, however it is possible for C++ arrays (std::array) and dynamic arrays (std::vector).
Topic archived. No new replies allowed.