int n[] = {1000,5000,100000,105000,400000,500000,505000,800000,995000,1000000};
int *array1 = new int[n[0]]; //1000
int *array2 = new int[n[1]]; //5000
Is this valid for creating array1
size 1000
and array2
size 5000
?
Even after programming for a year this stuff still trips me up.
And my second question: Is there any way to automatically set all values in each position to NULL or 0? Because after printing the array, the first chunk of numbers are:
1163089152
1330794578
1162627398
1547322173
1919251285
1766218867
7367020
1129595223
1128090959
1635212346
1836016500
1852405504
1030908260
1465662019
1868852841
29559
1625020798
134224442
4199212
4234532
4234544
4209436
4200378
4286800
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1910233198
134224636
1985292544
1985292576
1985292608
1985292640
1985292672
1985292704
1985292736
1985292768
1985292800
1985292832
1985292864
1985292896
1985292928
1985292960
1985292992
1985293024
1985293056
1985293088
1985293120
1985293152
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
... .... .....
And in my current assignment efficiency is key. Looping through 1000 elements just to set them to 0 or NULL seems...inefficient
EDIT: Problem solved, thank you all for the speedy answers!