This is a recursive function in C (function call itself) the Main case is:
and is returned a value of variable “i” that must be 6 but is 1 as explaned:
if(i==6){return i;} but the value returned is 1 not 6…
note that i must be == 6 to exevute
return…
Here is the code:
#include<stdio.h>
int func1(int i){
if(i == 6) { // Base Case
printf("nEnd1");
return i;
}
printf("%d ", i);
func1(i + 1);
// printf("nEnd1");
return i;
}
int main()
{
printf("n%d", func1(1));
return 0;
}
I receive 1 as i value instead of 6.
this is my Output:
1 2 3 4 5
End1
1
Expected Output:
1 2 3 4 5
End1
6
I don’t know where to throw the head…
Any Solution?
The following link open a new website page click here↗???? to view the code run.
(this qestion follows what asked in “C Multiple Func() printf – With no Reason”.
pvt-Tron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.