passing bool array to a function
I am passing a bool array to function and doing some modifications in the
passed array inside the function, the changes that I do in the function
are reflected in the original array that I passed to the function.For
example ,in the code below the output is 1 .Why am I getting this output ?
When we pass an integer variable for example ,the local variable maintains
its local value .How can I retain local copy of the original bool array
locally in the code below.
#include<iostream>
using namespace std;
void fun(bool A[30])
{
A[0]=true;
}
int main()
{
bool used[3];
used[0]=used[1]=used[2]=0;
fun(used);
cout<<used[0];
}
No comments:
Post a Comment