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 8898649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:39:48+00:00 2026-06-15T00:39:48+00:00

If I have to write some code like below: int a[10000000]; I know that

  • 0

If I have to write some code like below:

int a[10000000];

I know that the code might fail sometimes due to stack overflows. The question is how to handle such errors at runtime, and avoid the segfault?

  • 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-15T00:39:50+00:00Added an answer on June 15, 2026 at 12:39 am

    In general, stack overflow exceptions are very difficult to handle in a graceful way. This is because the stack is already overflowed, and in order for more code (even exception handling code) to run there needs to be stack space available.

    In general, programmers design programs so that they cannot overflow the stack. This involves:

    • keeping the size of automatic variables allocated on the stack to a minimum (and using other types of allocation if large data structures are needed)
    • avoiding unnecessary recursion, and if recursion is used, ensuring that there are reasonable constraints on the maximum depth

    If you need space for ten million integers inside a function, don’t allocate it on the stack – allocate it using malloc() or new (depending on whether you are actually using C or C++). Of course it is also your responsibility to free() or delete it when you are done with it.

    If you are really using C++[1], then you should probably be using std::vector instead:

    std::vector a(10000000);
    

    The underlying standard library implementation will allocate the space on the free store, and will automatically deallocate it for you when your function returns.

    [1] I wish people wouldn’t tag questions with both c and c++ just because they are spelled similarly.

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

Sidebar

Related Questions

I'd like to write a function that would have some optional code to be
So far I have managed to write some code that should print the source
Suppose I have this database table (some sample code below) that stores the relationship
I have been trying to write some code in Scala to read a file
Question simple and quick: I have started to use Netbeans to write some code
I'm trying to write some C# code to do administration on IIS. I have
I have a couple of web-pages where I write out some code c# ,
I currently using android NDK to write some native code in C. I have
I found some code from the msdn site (Code included below), which looks like
if i want to write a procedure like below, is there some other way

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.