1 votes 1 votes main { int i; printf (“Hellow \n”); For(i=1; j<=10; i++) main ( ); } What is the o/p of the following program? Endless execution of code & printing Hellow continuously Compiler error Hellow 10 time Hellow 9 times Programming in C programming-in-c output programming + – Parshu gate asked Nov 10, 2017 • edited Mar 14, 2019 by Naveen Kumar 3 Parshu gate 1.0k views answer comment Share Follow See 1 comment See all 1 1 comment reply Rishabh Gupta 2 commented Nov 10, 2017 reply Follow Share There are so many errors in this code: main () <- missing parenthesis after main For <- function not defined, it should be "for" j <= 10 <- j is not defined, it should be i. If all these are corrected, the program will keep running until the stack memory is exhausted. 1 votes 1 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes Inside the main function , it will print Hello, then for the loop from i=1 to 10, it will execute main i.e. it will print Hello 10 times then again it will print Hello another 10 times and will continue printing endlessly Sayan Bose answered Nov 10, 2017 • selected Nov 12, 2017 by Parshu gate Sayan Bose comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments Sayan Bose commented Nov 10, 2017 reply Follow Share I compiled this on Dev C Compiler and it is printing "Hello" inifinitely. Hope this answers your question - #include<stdio.h> int main() { int i; printf("Hello \n"); for(i=1;i<=10;i++) main(); return 0; } 0 votes 0 votes Parshu gate commented Nov 10, 2017 reply Follow Share My doubt is in for loop they gave 'j' which isn't declared at all. So that will be an error right? 0 votes 0 votes Sayan Bose commented Nov 10, 2017 reply Follow Share That would be i. They wouldn't intentionally make an error so trivial 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes Endless execution of code & printing Hellow continuously Explanation: When control enters in main( ) it meets printf( ) & promptly prints the message. Then in for loop it calls main again. Recursion starts for i=1. Again there will be a print execution & for i=1, the recursion repeats. This goes on & on until either we don’t abort the execution by pressing ctrl+C. mohitbawankar answered Dec 11, 2017 mohitbawankar comment Share Follow See all 0 reply Please log in or register to add a comment.