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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:05:13+00:00 2026-05-17T18:05:13+00:00

i wanted to declare a very large array. i found that the max size

  • 0

i wanted to declare a very large array. i found that the max size of an array is size_t, which is defined as UINT_MAX

so i wrote the code like this

int arr[UINT_MAX];

when i compile this, it says overflow in array dimension

but when i write like this

size_t s = UINT_MAX;
int arr[s]; 

it compiles properly.
what’s the difference

  • 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-05-17T18:05:13+00:00Added an answer on May 17, 2026 at 6:05 pm

    First error: size_t is not necessarily unsigned int, thus its maximum value can be different from the one of unsigned int (UINT_MAX); moreover, in C++ to get informations about the limits of a type you should use std::numeric_limits.

    #include <limits>
    
    size_t s=std::numeric_limits<size_t>::max();
    

    Second error: you won’t ever get an array so big; since size_t is required to be able to express the biggest size of any object, it should probably big enough to express an object big as the whole address space available to the application, but trying to allocate such a big object would require to dedicate the whole address space to it, which is infeasible; moreover, you’re requesting an array of ints that big, which means that it will be UINT_MAX*sizeof(int) bytes big, which will probably be about 4 times the whole address space – clearly nonsense – and by the way sizeof(arr) wouldn’t be able to express the size of such object, and in general pointers couldn’t even reach the top of that array. The compiler detects these faults and stop you from doing that.

    Moreover, I infer that you’re trying to allocate that thing on the stack, that is usually much much smaller than all the memory that the application can use, and in general it’s not a good idea to allocate big arrays there (you should use the heap for that).

    Third error: allocating all that memory doesn’t make sense. If you have big memory requirements, you should allocate stuff on the heap, not on the stack, and allocate just the memory you need to play along well with the OS and the other applications (this last consideration do not apply if you’re working on embedded systems where you are the only application that is running).

    The second snippet in C++ shouldn’t even work, since, if that thing is allocated on the stack, you’re going nonstandard, since it would be a VLA (available in C99 but strongly rejected from the current and the next C++ standard). However, in that case the code to allocate that array is used at runtime (VLAs in general are not fixed in dimensions), so the check for the compiler is not obvious to do (although I suppose that this thing could be spotted easily by the optimizer, which, if VLA semantic is not different from regular arrays, could optimize away the VLA and try to make a regular array => which would fail for the same reasons I stated).

    Long story short: it makes no sense to allocate all that memory (that you couldn’t even address), especially on the stack. Use the heap and allocate just what you need. If you have special requirements, you should investigate the special virtual memory functions provided by your OS.

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

Sidebar

Related Questions

I wanted some of those spiffy rounded corners for a web project that I'm
I wanted to generate one fix view using interface builder, but the size of
just wanted to gather different ideas and perspectives as to which layer should (and
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>
Wanted to get some consensus around a UI feature I'm working on right now.
I wanted to show the users Name Address (see www.ipchicken.com ), but the only
I wanted to emulate a popular flash game, Chrontron, in C++ and needed some
Just wanted to get an idea for ways (web) developers get round the short
I wanted to do something like this: <asp:Label ID=lblMyLabel onclick=lblMyLabel_Click runat=server>My Label</asp:Label> I know
I wanted to edit a log comment in the repository browser and received an

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.