484 views
0 votes
0 votes
#include<stdio.h>

int f();

int main(){
    printf("hello");
    int a=f();
    printf("%d",a);
    return 0;
}

int f(){
    main();
    return 8;
}

Why is 8 not printed here? I am a bit confused that after f returns, it returns 8, so a must be assigned 8. Then how come it is not getting printed?

2 Answers

2 votes
2 votes
Because the print statement will never be executed. Until the stack overflow there will be call from main to function f and vice-versa.
0 votes
0 votes

I have executed it in ideone nd it is showing infinite no of hello nd it should be bccause in the first line of the main function 

printf( "hello") will print a single hello.In the next line we r calling f() which is calling main() which first prints hello and then again calls f() and then main().............it goes on infinetly .....so the programm is not going to execute  

 printf("%d",a);
    return 0;

of main function ever and return 8 of f() function .so,a will never contain 8 nd 8 will never be printed .

calling main recursively should be avoided but using main recursively is not illegal. See the link 

http://stackoverflow.com/questions/21941040/calling-main-function-in-c

Related questions

2 votes
2 votes
3 answers
1
Laahithyaa VS asked Sep 9, 2023
934 views
. What will be the value returned by the following function, when it is called with 11?recur (int num){if ((num / 2)! = 0 ) return (recur (num/2) *10+num%2);else return 1...