dynamic memory allocation.. array larger than 10^6

Please help making an array or something that can hold larger than 10^6 elements in it. Also tell about vectors. Thank you!

if u declare an array of size 10^6 and using int as the data type then your program need 10^6 * 4 bytes of space Approx = 3GB of RAM. Systems having 2GB ram cannot supply this memory and results in segmentation fault.

declaring an array globally helps you in allocating space for 10^8 int’s but if you want to store big ints then this will be a problem

a program typically needs space for not more than 10^6 integers or anything.
else you might be doing something wrong.

if you are trying to use vectors instead of arrays keep in mind that operations on vectors are slower than operations on arrays.

apart from that you can learn about vectors HERE

please help on declaring an array globally. wud be happy if u provide the code!

@infinitum…not 3GB…it is arnd 3MB…10^6 is M and 10^9 is G…:stuck_out_tongue: