- Solution
We'll learn different approaches to solve the previous challenge.
Solution 1: Using Function Arguments
C++
// power1.cpp#include <iostream>int power(int m, int n){int r = 1;for(int k=1; k<=n; ++k) r*= m;return r;}int main(){std::cout << power(2,10) << std::endl;}
Explanation
We’re using a for loop to compute the power. The loop runs a total of n times by multiplying the number m by r for every iteration of the loop in line 7.
For a more in-depth insight into the solution above, click here. It shows how things are handled at the assembler level.
The critical point ...