Dec 5, 2009 at 1:15pm UTC
int a Function (int j, int& k)
{
do
{
j++;
k-=2;
} while (j <= k);
return j;
}
What is the output of the following code fragment?
int x = 3, y = 8;
x = aFunction (x,y);
cout << x << " " << y;
---------------------------------------------------
Is the answer 54?
Dec 5, 2009 at 1:29pm UTC
no the answer is
x = 5
y = 4
so on output it looks like: 5 4
cout << x << " " << y;
EDIT:
Last edited on Dec 5, 2009 at 2:00pm UTC
Dec 5, 2009 at 2:00pm UTC
basically because you declare:
x = aFunction(3, 8); <---- but the 8 is passed by what?
try this...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
using namespace std;
int aFunction(int j, int k);
int main()
{
int x = 3, y = 8;
x = aFunction (x,y);
cout << x << " " << y;
return 0;
}
int aFunction (int j, int k)
{
do
{
j++;
k-=2;
} while (j <= k);
return j;
}
What is the output of the following code fragment?
Last edited on Dec 5, 2009 at 2:14pm UTC
Dec 5, 2009 at 6:05pm UTC
well yes, but do you understand why ?
x = aFunction(3, 8); <---- but the 8 is passed by what?
Last edited on Dec 5, 2009 at 6:06pm UTC
Dec 6, 2009 at 1:40am UTC
Not to sure. I believe in
x = aFunction(3, 8); // y = 8 remains unchanged?