0

Why is there any output at all, and why is it: 0,1,2? How does it count up again?

https://code.sololearn.com/c2hl5kISgNcc/?ref=app

27th May 2019, 3:04 PM
De Buppetrellert
De Buppetrellert - avatar
2 odpowiedzi
+ 4
It has an output, because there is a printf function. It outputs in this order, because it runs the function first, before printing it. So it could be written like this: fun(--3); printf("%d", n); -> fun(--2); printf("%d", n); printf("%d", n); -> fun (--1); printf("%d", n); printf("%d", n); printf("%d", n); -> printf("%d", n); //Subtracted 1 3 times -> 3 - 3 = 0 printf("%d", n); //Subtracted 1 2 times -> 3 - 2 = 1 printf("%d", n); //Subtracted 1 once -> 3 - 1 = 2 (It has different values, because n is not static, so outside of the scope it won't exist)
27th May 2019, 3:42 PM
Airree
Airree - avatar
+ 1
I didn't know that a called function (In this case called several times) actually returnes to the rest of the code within and executes it, that wasn't in the first place, when it was let out before through a call of itself. I'm a little wiser now. :) Thank you all for clarifying this.
27th May 2019, 4:25 PM
De Buppetrellert
De Buppetrellert - avatar