search
Log In
0 votes
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++)

in Programming
retagged by
356 views
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 Answer

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

2 votes
1 answer
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?
asked Dec 11, 2018 in Algorithms Gangani_Son 571 views
5 votes
2 answers
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?
asked Nov 2, 2017 in Algorithms shaurya vardhan 662 views
4 votes
1 answer
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)?
asked Nov 2, 2017 in Algorithms shaurya vardhan 215 views
1 vote
0 answers
4
415 views
What is the time complexity for infinite loops Question 1 what is T(n) for this case While(1) { a=a+b; } Question 2 for this case if(1) { for i to n a=a+b } else { for i to n for j to n a=a+b } Edit 2: Compiled the code never goes to the else part ... %d",a,b); return 0; } output I get is 8 6 which means the else case is never executed hence in worst case do we have to consider the else part.
asked Nov 6, 2018 in Algorithms sripo 415 views
...