0

Can anyone explain this code

#include<stdio.h> int main(){ static int i=5; if(--i){ printf("%d",i); } main(10); return 0; }

22nd Jul 2020, 4:08 PM
Vanshika Dharwal
Vanshika Dharwal - avatar
5 Answers
+ 3
Vanshika Dharwal you are calling main() recursively inside of main() function itself without a base case so this should definately end up in a infinity loop. And also "i" is declared as static so it will not reinitialise everytime you are calling the main function thus will result in numbers till minus infinity (i.e. wherever int data type allows)
22nd Jul 2020, 4:12 PM
Arsenic
Arsenic - avatar
+ 2
shubham kumar surprisingly this does not generate any error.👇 https://code.sololearn.com/c5c2c1R7LZFQ/?ref=app I think the reason behind this is that main actually can take some arguments but they are generally provided by the operating system(or by programmer using command line arguments) And according to latest C/C++ standards , " The function main shall not be called explicitly within a program "
23rd Jul 2020, 1:42 PM
Arsenic
Arsenic - avatar
+ 1
Thank you 😊
22nd Jul 2020, 4:15 PM
Vanshika Dharwal
Vanshika Dharwal - avatar
+ 1
Your welcome 🙂👍
22nd Jul 2020, 4:18 PM
Arsenic
Arsenic - avatar
0
I think there will be error because in the main you placed argument.
23rd Jul 2020, 1:11 PM
shubham kumar
shubham kumar - avatar