for loop - Explain the output of a c program -
#include<stdio.h> main() { static int i=1; printf("\nsoftware"); for(;i<5;i++) main(); return 0; }
the output comes out infinite loop. please explain.
you calling main function main function. after call new main function print string , again call main function.
your i variable not incremented @ all, because not incremented in first iteration of loop. after call main, never return previous main next iteration of loop happen. loop infinite , i equal 1. if changed loop other loop, loop still infinite.
i'm including repaired code, fun of it:
#include<stdio.h> int main() { static int i=0; if(i>=5) return 0; i++; printf("\nsoftware %i", i); main(); return 0; }
Comments
Post a Comment