Recall that the static
variable is shared between all calls to main
. Then consider the code as it is executed recursively:
int main() {
static int i = 5; // 5
if (--i) { // 4
main() {
if (--i) { // 3
main() {
if (--i) { // 2
main() {
if (--i) { // 1
main() {
if (--i) // 0 (false)
return 0;
}
printf("%d ",i); // 0
}
return 0;
}
printf("%d ",i); // 0
}
return 0;
}
printf("%d ",i); // 0
}
return 0;
}
printf("%d ",i); // 0
}
return 0;
}
1
solved How does this program execute? [duplicate]