+ 1
What is the output of this question? I dont know how to solve this question please explain me
9 Antworten
+ 7
This is recursion program and function calling again and again when u passing 5 in function it will check condition if condition is true then if statement will work if false then else will execute if part will be execute when number ==0 but in else part again function calling and it will decrease by 1 all times return will print values after one by one
+ 3
Each recursive call creates a new copy of that method in the memory. Once some data is returned by the method, the copy is removed from the memory. Since all the variables and other stuff declared inside function get stored in the stack, therefore a separate stack is maintained at each recursive call. Once the value is returned from the corresponding function, the stack gets destroyed. Recursion involves so much complexity in resolving and tracking the values at each recursive call. Therefore we need to maintain the stack and track the values of the variables defined in the stack
this recursive function for n =5. First, all the stacks are maintained which prints the corresponding value of n until n becomes 0, Once the termination condition is reached, the stacks get destroyed one by one by returning 0 to its calling stack.
+ 2
To correct it call prinf before you call loop(i-1).
Step 1-You call loop(5).
Step 2-Go else... Then it call loop(4)
Step 3-Then go else again and call 4-loop(3)...
Up to i==0 and print(0).
But all got stack, remember all print on else? Command continue.
Then back where did you called. Printing 1...
Back Step 3, printing 3.
Then back step 2 printing 4.
Then back step 1 printing 5.
+ 2
To unserstand it try:
#include <stdio.h>
void callingOne()
{
printf("Called one\n");
}
void callingTwo()
{
printf("Before calling One\n");
callingOne();
printf("After calling one\n");
}
int main() {
printf("Before call two\n");
callingTwo();
printf("After call two\n");
return 0;
}
+ 2
So, start at main.
Main call callingTwo.
Calling two star running and call callingOne
Calling one start running.
When it end, it back where was called, at callingTwo.
Then callingTwo end and back to main.
+ 1
Any one can clear this doubt?
0
When loopy(i-1);
Printf(i);
I think print values are 54321
0
But output are 012345
0
Basically doubt not clear