I am a learner and new to C language. While I was creating a function which will give power of two numbers using for loop I encounter that using int declaration before loop
For the first piece of code, r = r * x refers to the r defined outside the for loop, which means it works as expected. For the second piece of code, when you do int r = r * x, you're declaring another r scoped to the for loop, and the changes are not reflected in the outer r. Then, outside the for loop, you switch back to the outer r, which is still 1.