Run Output
65 11 65 13 65
Let us begin by function which is called first in the main()
void fn2(int x[],int y=10) //Here array initialised in main with 1,2,3,4,5 is called by reference
{
for(int i=0;i<5;++i) //Fixed traversing size of 5 has been given
x[i]=y++;
value of x[i] after each iteration would be 10,11,12,13,14 as the y would post increment.
fn1(x); //Now we shall understand fn1 and then new values.
}
void fn1(int p[],char q=’A’) //another function which is called from fn2. It can be directly called in fn2 as it has been written above it and its reference would be available to fn2. Here function seems to again pass the same array by reference and a character variable q with default value ‘A’ has been passed.
{
for(int i=0;i<5;++i) //5 iterations will happen
if(p[i]%2==0) p[i]=q;
This will test divisibility by 2 and which ever member is divisible by 2 will be replaced by value of q. Since the value of q is ‘A’ it will get filled as numeric value 65 (ascii code of A) because the target array is an integer array. So after each iteration of array which now has 10,11,12,13,14 all the even numbers will be replaced by 65. The array will now become
65 11 65 13 65
The output will be printed in the main routine using the following line.
for(int i=0;i<5;i++) cout<<a[i]<<” “;