```
//Hi all ,can you explain why does this functon has two returns?
//How to read them? Is it like if/else?
int _tmain(int argc, _TCHAR* argv[])
{
int x, n;
int res;
int power(int, int);
cout << "Enter a number:";
cin >> x;
cout << "Enter a power:";
cin >> n;
res = power(x, n);
cout << "X^N is:" << res << endl;
return 0;
}
int power(int x, int n)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return power(x*x, n / 2);
return power(x*x, n / 2)*x;
}
```

## Recommended Answers

Jump to PostThe

`power`

function has three returns. The first is inside the first`if`

, the second (which is wrongly indented) is inside the second`if`

and the third is outside of any`if`

. The third will only execute if none of the previous`if`

s were executed (just like the second will …

## All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.