Question:
large size array declaration in turbo c++?
Goku
2013-01-27 00:41:52 UTC
i need to declare an array consisting of non-negative integers. i need to keep the upper limit of array size as 10^9. how to go about this?
Three answers:
t
2013-01-27 02:01:05 UTC
You can try to dynamically allocate the array, though it will probably fail because you won't have enough memory:



    int * arr = new int[1000000000];

    // use arr

    delete arr;



If the array is sparse (you only use some of the indices), consider using the STL map (http://www.cplusplus.com/reference/map/map/ ). Example:



    map m;

    m[0] = 42;

    m[999999999] = 42;

    printf("%d %d\n", m[0], m[999999999]); // output: 42 42
Param
2013-01-27 00:47:45 UTC
U cant store that much numbers in the array....

It may exceed the block size allotted for the program...

For better programming use some other data structure like linked list....Use Dynamic Memory allocation to store the integers....
2016-12-11 12:36:08 UTC
the 1st set of code is as follows: int MyList[40 8]; int MyList[0] = {a million,2,3,4}; int MyList[a million] = {3,4,5,6,2,3,a million}; you have decalred an integer array of length 40 8, yet to each and each element you're assigning an int array. it rather is rather not impressive. The task could be of the type MyList[0]=2; added diverse declarations for MyList is there. So this code isn't conceivable. the 2nd set of code is given below: int *checklist[40 8]; int checklist[0] = {a million,2,3,4}; int checklist[a million] = {2,3,4,5,6,7,8,9}; The mening of the 1st assertion is checklist is an array of 40 8 guidance to integer, provided that [] has a extra physically powerful priority than *. needless to say it rather is rather not what you decide on. What we want is that we could continually declare a pointer to a ten element integer array, assuming that the optimal length of a subarray is 10, whilst 40 8 such subarrays are to be saved with archives. int *(MyList[10]);// here MyList is a pointer to an array of 10 integers, the max length of the sub array. Now we are able to create the subarray as int ML1[10]={a million,2,3,4}; int ML2[10] = {2,3,4,5,6,7,8,9}; ML1 is composed of the handle of array {a million,2,3,4} and it rather is in lots of situations assignd to the pointer MyList[0] ML2 is composed of the handle of array {2,3,4,5,6,7,8,9} and it rather is in lots of situations assignd to the pointer MyList[a million]. similary we are able to assign different sub arrays. you are able to locate that the determine 40 8 would not look everywhere in our code. it rather is rather not necessary provided that, the memory is allotted as much as we want, one by skill of one. Use of this code, in assigning archives to the arrayand showing the assigned archives is given interior here code. ------- code ------- # comprise #comprise void important() { int *(MyList[10]);/* MyList is pointer to an array of 10 int*/ int ML1[10]={a million,2,3,4};/* we are no longer totally using the technique of 10 int*/ int ML2[10] = {2,3,4,5,6,7,8,9}; /* in addition you are able to declare different guy or woman arrays int ML3[10]={11,12,13,14}; .. .. */ int i,j,jmax; MyList[0] = ML1;/* assigns the handle of sub array a million to MyList[0]*/ MyList[a million] = ML2; /* in addition you are able to assign different array handle MyList[2]=ML3; etc */ clrscr(); for (i=0;i<2;i++) { if(i==0) jmax = 4;/* length of MyList[0] array*/ if (i==a million) jmax = 8;/* length of MyList[a million] array*/ /* in addition provide the sizes of different arrays if(i==2) jmax = 4; etc. */ for (j=0;j


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...