Feb 9, 2007 #1 M manish12 Advanced Member level 3 Joined Nov 21, 2006 Messages 983 Helped 66 Reputation 132 Reaction score 33 Trophy points 1,308 Activity points 6,117 Array declaration in C++ WHY THIS PROGRAM DONT WORK? Here if I declare arr[100][100] then it works, but if I increase array size to 1000, it don't? #include<iostream> using namespace std; int main() { int i,j; double arr[1000][1000]; for (i=1;i<=1000;i++) for(j=1;j<=1000;j++) cout<<a[j]<<endl; return 0; }
Array declaration in C++ WHY THIS PROGRAM DONT WORK? Here if I declare arr[100][100] then it works, but if I increase array size to 1000, it don't? #include<iostream> using namespace std; int main() { int i,j; double arr[1000][1000]; for (i=1;i<=1000;i++) for(j=1;j<=1000;j++) cout<<a[j]<<endl; return 0; }
Feb 9, 2007 #2 johnyaya Full Member level 2 Joined May 30, 2001 Messages 125 Helped 17 Reputation 34 Reaction score 0 Trophy points 1,296 Location YoyoDyne Activity points 1,106 Re: Array declaration in C++ 100 * 100 = 10,000 items in the array (0x2710), 10K * 8 bytes = 80 Kbytes 1000 * 1000 = 1,000,000 items in the array (0xF4240), 1M * 8 bytes = 8 Mbytes Too large of array? Does 250 x 250 array work (250 * 250 = 62500 or 0xF424)? Does 300 x 300 array fail (300 * 300 = 90000 or 0x15F90)?
Re: Array declaration in C++ 100 * 100 = 10,000 items in the array (0x2710), 10K * 8 bytes = 80 Kbytes 1000 * 1000 = 1,000,000 items in the array (0xF4240), 1M * 8 bytes = 8 Mbytes Too large of array? Does 250 x 250 array work (250 * 250 = 62500 or 0xF424)? Does 300 x 300 array fail (300 * 300 = 90000 or 0x15F90)?
Feb 9, 2007 #3 R rmitoday Newbie level 4 Joined Aug 15, 2006 Messages 6 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,315 Array declaration in C++ You should use memory allocation functions instead of array for big data. double *p = new double[1000*1000]; works well.
Array declaration in C++ You should use memory allocation functions instead of array for big data. double *p = new double[1000*1000]; works well.
Feb 11, 2007 #4 dragonight_x Member level 4 Joined Mar 25, 2006 Messages 71 Helped 2 Reputation 4 Reaction score 0 Trophy points 1,286 Location Egypt - Cairo Activity points 1,667 Re: Array declaration in C++ Well, [1000] [1000] is just too big!!!! As “rmitoday” says try memory allocation
Re: Array declaration in C++ Well, [1000] [1000] is just too big!!!! As “rmitoday” says try memory allocation
Feb 13, 2007 #5 S sohailshahzad Junior Member level 3 Joined Jul 13, 2006 Messages 30 Helped 2 Reputation 4 Reaction score 0 Trophy points 1,286 Activity points 1,410 Re: Array declaration in C++ Always use the dynamic allocation of memory for the large data size use the malaloc fun
Re: Array declaration in C++ Always use the dynamic allocation of memory for the large data size use the malaloc fun
Feb 15, 2007 #6 R rp_istec Newbie level 4 Joined Dec 19, 2006 Messages 5 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,304 Re: Array declaration in C++ #include<iostream> using namespace std; int main() { int i,j; double arr[1000][1000]; for (i=1;i<=1000;i++) for(j=1;j<=1000;j++) cout<<a[j]<<endl; return 0; } size of 1000 means go from 0 to 999, so use this for (i=0;i<1000;i++) for(j=0;j<1000;j++) Rolf
Re: Array declaration in C++ #include<iostream> using namespace std; int main() { int i,j; double arr[1000][1000]; for (i=1;i<=1000;i++) for(j=1;j<=1000;j++) cout<<a[j]<<endl; return 0; } size of 1000 means go from 0 to 999, so use this for (i=0;i<1000;i++) for(j=0;j<1000;j++) Rolf
Feb 18, 2007 #7 M mondunno Advanced Member level 4 Joined Jan 11, 2007 Messages 119 Helped 15 Reputation 30 Reaction score 4 Trophy points 1,298 Activity points 1,907 Array declaration in C++ u're right rolf,
Feb 19, 2007 #8 K Koson Junior Member level 2 Joined Oct 4, 2006 Messages 21 Helped 2 Reputation 4 Reaction score 2 Trophy points 1,283 Location Bangkok, Thailand. Activity points 1,370 Array declaration in C++ don't be forget to initial those variable, a[][], before using them in the cout << ...;
Array declaration in C++ don't be forget to initial those variable, a[][], before using them in the cout << ...;