+ 2

Can anyone tell and explain the output of following code?

#include<stdio.h> int main() { printf("Hi") ; main() ; return 0 ; }

7th May 2018, 7:41 AM
Amit Kumar
Amit Kumar - avatar
9 ответов
+ 4
Amit kumar This is called recursion of a function. Due to the second main() the first main() is called again and again (infinite times). Therefore, everything written in between these two mains gets also executed repeatedly. That's why "hi" is printed infinite time.
16th May 2018, 9:17 AM
Çůřîöş ßąšäñț 🇮🇳
Çůřîöş ßąšäñț 🇮🇳 - avatar
+ 2
that is C program to print "Hi" on screen for more details https://www.sololearn.com/learn/1344/?ref=app
7th May 2018, 7:56 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
actually output is hihihihi.... infinite times CAN ANYONE EXPLAIN WHY??
7th May 2018, 3:59 PM
Amit Kumar
Amit Kumar - avatar
+ 1
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
7th May 2018, 4:00 PM
abdiwahab jama said
abdiwahab jama said - avatar
+ 1
i actually not get to know what is happening due to second main() CAN ANYONE HELP ME TO FIND OUT??
7th May 2018, 4:05 PM
Amit Kumar
Amit Kumar - avatar
16th May 2018, 12:40 PM
Amit Kumar
Amit Kumar - avatar
0
Hi
7th May 2018, 3:57 PM
Vincent Sipoi
Vincent Sipoi - avatar
0
The second main function might be causing it... You can try running it without and see what happens
7th May 2018, 4:03 PM
Vincent Sipoi
Vincent Sipoi - avatar
- 1
hi
7th May 2018, 10:33 AM
abdiwahab jama said
abdiwahab jama said - avatar