Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix an array declaration program in C++

Status
Not open for further replies.

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;
}
 

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)?
 

Array declaration in C++

You should use memory allocation functions instead of array for big data.

double *p = new double[1000*1000];

works well.
 

Re: Array declaration in C++

Well, [1000] [1000] is just too big!!!! As “rmitoday” says try memory allocation
 

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++

#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
 

Array declaration in C++

u're right rolf,
 

Array declaration in C++

don't be forget to initial those variable, a[][], before using them in the cout << ...;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top