Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8934953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:53:18+00:00 2026-06-15T09:53:18+00:00

Possible Duplicate: What is a stack overflow error? look the code below. #include <iostream>

  • 0

Possible Duplicate:
What is a stack overflow error?

look the code below.

#include <iostream>
using namespace std;

void leave(double as){
    cout<<as;
    leave(as);
}


int main(){
    double x=1234.5;
    leave(x);
    cout<<"hellow";
}

When this code executes their is no way to stop. it should print the value x over and over again. But practically, this works for about 20 secs and close automatically. It doesn’t print the line hellow. What is the reason for it? In windows task manager I can realize that the memory used with the application will increase. but I have allocated memory for x within the main function only, so will the function allocate memory for x over and over again. Is this type of situation called a memory leak? if its so what lines should be added to prevent it?

If I change the code as below it shows the word hellow without going through the function over and over again:

 void leave(){
     leave();
  }

  int main(){
      leave();
      cout<<"hellow";
  }

How to explain these situations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:53:19+00:00Added an answer on June 15, 2026 at 9:53 am

    Every call to leave() results in adding a little information to the stack. When you call it recursively, the stack grows until it runs out of space, and the operating system terminates the application. In the second example, presumably the compiler optimized out the function that did nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is a stack overflow error? Can any one tell me how
Possible Duplicate: Using Source Control So, although even here on Stack Overflow are literally
Possible Duplicate: Stack overflow visual C++, potentially array size? This code is simply meant
Possible Duplicate: Syntax highlighting code with Javascript I have noticed that Stack Overflow uses
Possible Duplicate: What does ^ in objective C mean? [SKSite requestSiteWithNameLike:@Stack Overflow completionHandler:^(SKSite *site,
Possible Duplicate: What is the difference between a stack overflow and buffer overflow ?
Possible Duplicate: Stack Overflow / reddit voting system in php How do voting systems,
Possible Duplicate: Enums returning int value I want to numerate Stack , Overflow and
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.