# Self Doubt:Infinite loop

356 views
#include<iostream>
using namespace std;

int i=0;
void a()
{
i+=1;
cout<<i<< ".hello"<<endl;
a();
}

int main()
{
a();
}

For this above code the output is only upto →  64891.Hello

Does this mean that that the stack can hold only 64891 recursive calls? (I am using dev c++)

retagged
0
showing error :(
0
It runs perfectly in dev c++ .. 😶
0
how?? dry run code and tell me how running correctly?
0
we are calling a() infinite times and it prints.. 1.hello 2.hello 3.hello and so on
0
yes, then is it not stack overflow error??
0
ya..it is stack overflow..but output should be printed upto a certain point right?
0
upto infinity, no certain point there
0
dev gives output upto 64891.. and my question is also based on this that why upto 64891? is the stack capacity only that?
0

43169.hello

--------------------------------
Process exited after 54.19 seconds with return value 3221225725
Press any key to continue . . .

mine exited like this

1 vote
I run the same code in ubuntu terminal and each time I executed the code, it shows me a different value of 'i' around 5 lakhs with a message segmentation fault (core dumped)

## Related questions

1
571 views
#include <stdio.h> void print(int n, int j) { if (j >= n) return; if (n-j > 0 && n-j >= j) printf("%d %dn", j, n-j); print(n, j+1); } int main() { int n = 8; print(n, 1); } (A) 1 7 2 6 3 5 4 4 4 4 (B) 1 7 2 6 3 5 4 4 (C) 1 7 2 6 3 5 (D) 1 2 3 4 5 6 7 8 Answer is B. anyone can explain how?
2
662 views
Consider the following function Void func(int n){ Int k=n; Int i=0; for(;i<n;i++){ while(k>1){ k>>=1; } } What is the worst case time complexity of the function?
3
215 views
Consider the following code….. Search(int n){ if(n<2) then return; else{ s=0; for(i=1;i<=8;i++){ Search(n/2); } for(i=1;i<n*n;i++){ for(j=1;j<n;j=j*2){ s=s+i; } } } } Assume s is a global variable.Find the complexity of the given Search(n)?
1 vote