Discussion in 'BlackHat Lounge' started by Designerdude13, Oct 3, 2012.

1. ### Designerdude13Power Member

Joined:
Nov 22, 2010
Messages:
648
194
Gender:
Male
Code:
```#include <iostream>
using namespace std;

int f(int x);
int g(int x);

int main()
{
int x = 1;
cout << f(x) + g(x);
return 0;
}

int f(int x)

{
x = x + 1;
cout << x;
return g(x);
}

int g(int x)

{
x = x + 1;
cout << x;
return x;
}```
Okay I don't see how this prints out 2325

I've started out by doing this
f(x)
1 + 1 equals 2...then I sent the value to g(x)

now for g(x) x equals 2 + 1 which is 3
....now i returned 3 back to main...but i dont see how 5 is coming into play with this? I also thought that you can't return values to main???

Last edited: Oct 3, 2012
2. ### umerjutt00Jr. VIPJr. VIP

Joined:
Oct 28, 2011
Messages:
4,052
2,270
Occupation:
Ninja
I don't even know the ABC of C++. I tried to learn C++ 2 months ago but left it because of not having enough time.

3. ### zoulouNewbie

Joined:
Oct 29, 2008
Messages:
20
2
In have in the order :

in the main :
from f(x) -> cout << x -> which gives 2
then it goes to g(x) from f(x) where you have cout<< x -> which gives 3
at this moment bear in mind that f(x) return 3

you're now back in the main :
from g(x) -> cout << x -> which gives 2
and g(x) return 2

and finally you have cout << f(x) + g(x) that gives 3 + 2 = 5

So the output is 2325.

The idea is to understand that from the main, you evaluate f(x) (and in this f(x) you have also a g(x)), then g(x) and then cout<<f(x) + g(x).
I hope it's not too confusing.

4. ### safexJr. VIPJr. VIP

Joined:
Dec 28, 2009
Messages:
3,814
573
Occupation:
Search Engine Optimization
Better watch some Video Tutorial about C++ to get proper solution of your problem..

5. ### Designerdude13Power Member

Joined:
Nov 22, 2010
Messages:
648
194
Gender:
Male

YES! Thank you

6. ### 0scan0Junior Member

Joined:
Apr 9, 2010
Messages:
166
42
Location:
1.1.3
How is the exam structured? Home exam? In that case you could just hire someone over at fiverr or craigslist to do the work for you.

Joined:
Nov 22, 2010
Messages:
648