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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:41:51+00:00 2026-06-03T03:41:51+00:00

I am really new to C++ programming so please pardon my silly question. I

  • 0

I am really new to C++ programming so please pardon my silly question.

I have an array that looks like this:

double myarray [15][20000]; // Works ok but stack overflow error if I change 15 to about 200

I would like to achieve something like this:

double myarray [total][20000];

then at runtime I want user to input the value of total:

cin>>total

Please advice on how to acheive this and what is the best practice to solve this and avoid stack overflow.

Thanks.

  • 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-03T03:41:52+00:00Added an answer on June 3, 2026 at 3:41 am

    Use a vector of vectors:

    int total;
    
    cin >> total;
    
    //                                      (1)                        (2)
    std::vector<std::vector<double>> myVec(total, std::vector<double>(20000));
    // (1) is the first dimension and (2) is the second dimension
    

    And you can use them just like an array, and you won’t get a stack overflow:

    myVec[0][4] = 53.24;
    cout << myVec[0][4];
    

    And you can even make them bigger on the fly if you need to.

    You’re getting a stack overflow because the stack is usually pretty small and you are trying to allocate too big an array on it. vector uses dynamically allocated memory on the free store which is usually much bigger and won’t give you an overflow error.

    Also, in C++ the size of static arrays must be known at compile time which is why you can’t read in a number and use that, whereas with vectors you can resize them at runtime.

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

Sidebar

Related Questions

I'm really new to programming, so I'm having trouble explaining this -- please forgive.
This is a kind of a newb question but I'm really new to programming
Please forgive me if this question is ridiculous. I'm relatively new to programming and
I really need your help for this. I am relatively new to programming and
I'm new to web programming in general so this is probably a really simple
First of all, i'm a Graphic designer so please ignore if this programming question
I am really new in android programming. My question is how does RatingBar actually
Please do flog me for this really basic question, but I still can not
I’m very new to programming with RSS feeds to please forgive me if this
Before I start let me just say that I'm really new to programming so

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.