Size of arrays,vectors and dynamic array

what is the maximum possible size of a an array vector or dynamic array both local and global

Hi @Namanjain123
This depends on many factors, with the biggest one being how the array is represented.

If it’s a simple C-style in-memory array, the answer is fairly straightforward:

  1. If it’s a globally-declared, non-dynamic array, it will actually be part of the size of the executable itself in most implementations. In this case, any limits on the maximum size of an executable will define the upper limit of the array size.
  2. If it’s an array declared inside a function, the maximum size is a function of the amount of stack space available: Stack overflow. Note that this won’t be a constant, but is a function of the size of the Call stack when the stack containing the array is created, typically when the function containing the array is called.
  3. If the array is created dynamically using malloc or a related dynamic memory allocator, the maximum size is the max RAM + swap space available at the moment of allocation.
  4. A practical upper bound is the size of array indices. If your array index is 32 bit, your array can have at most 2^32 elements, if it’s 64 bit, your array can have at most 2^64 elements. However, the above memory constraints are typically hit long before this is an issue.

if i want to use them in ques then what sholud be the maximum permissible size for using them

@Namanjain123
Usually 1-D array of size 10^6 or 7 works fine

@Namanjain123
Usually 1-D array of size 10^6 or 7 works fine

and dynamic and vectors?

@Namanjain123
For dynamic array also 10^6 or 7 works fine. And for vector no need to declare it with size because as you keep pushing element in vector then vector will itself increase it’s size.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.