Please explain how to get the output

Please explain this to me

Find the output of the following programme:
# include < iostream.h>
void Withdef (int HisNum = 30)
{
for (int 1=20 ; I<*= HisNum; I+=5)
cout<<I<<””;
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main ()
{
int YourNum=20;
Control (YourNum);
Withdef();
cout<<”Number=”<<YourNum<<endl;
}
There are a lot of errors in this code.
# include <iostream.h>
This is deprecated (and, in fact, in won't even compile on many newer compilers). Use #include <iostream> instead.
1
2
3
4
5
6
void Withdef (int HisNum = 30)
{
    for (int 1=20 ; I<*= HisNum; I+=5)
        cout<<I<<””;
    cout<<endl;
}

First of all, you have a 1 instead of an I in your for loop initialization statement.
I'm not sure what I<*= HisNum; is supposed to be, but I think that's supposed to be I <= HisNum;.
Also, the line after that contains some weird quote characters (”” instead of "").
And finally, void main() is not, and never was, valid C++.
It should be int main().

Okay, now, for your actual program (after fixing those errors).
Your program declares a variable named YourNum and initializes it to 20.
It then passes it to the Control function, which increments it by 10 (raising its value to 30) and then calls Withdef on it.
Withdef prints all of the multiples of 5 between 20 and HisNum (which is 30), so it'll print 20, 25, and 30.
Finally, control returns to the Control function, which returns to main, which calls Withdef again.
This time, Withdef uses the default value for HisNum since nothing was passed to it, but since that value is also 30, it'll print 20, 25, and 30 again.
Then, the program returns to main and prints out the value of YourNum, which is 30 because it was modified in the Control function.
Thank you very much
Topic archived. No new replies allowed.