Explanation of a recursion program through an image

Olivier Guyot
Feb 10, 2021

--

Hello, if you can’t understand what happened in the stack by executing this code :

float _pow_recursion(float x, float y)
{
if (y == 0)
return (1);
return (_pow_recursion(x, y - 1) * x);
}

Look at those images example for Y = 4 and x = 2, is it better?

Fill the stack to stop at base case

Clear the stack to get the result

The 2 in red at each step is the x value.

I know, it may not be easy to understand, contact me, if you need more explanation :D

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Olivier Guyot
Olivier Guyot

No responses yet

Write a response