i have to declare an integer array, float array ,and character array of 85020 indexes..when im declaring it ..my compiler is giving error that array size is too large.

please tell me how can i declare array of this size.

<iostream>
<conio.h>

int main()
{

int a[85020];

float b[85020];

char c[85020];

getch();

}

Edited 5 Years Ago by AmerJamil: n/a

frogboy @ :( still having problem by reading your thread

Edited 5 Years Ago by AmerJamil: n/a

int size = 85020;
int* array = new int[size];

//..utilize array

delete [] array; //release memory for later use

well i think pointer is used in your thread..im not allowed to use pointer in my assignment. please see my following code ,it is working fine for the int and char array but giving error of large array size in float only

#include <iostream>
#include <conio.h>

void main()
{
const int size=85020;

int b[size];

char c[size];


float f[size];

getch();

}
int* array = new int[size];

whats this *? is this pointer used? well i hvnt studied pointers yet in my Programming Fundamental course..so ill not be allowed to use it

well i think pointer is used in your thread..im not allowed to use pointer in my assignment. please see my following code ,it is working fine for the int and char array but giving error of large array size in float only

Your code looks fine. If you're out of stack memory and you're not allowed to use "new" to take advantage of the heap, then you may be out of luck. What's the exact error?

The other option is some other tool that uses the heap, but does so behind the scenes without you needing to know how (i.e. vectors, as frogboy mentioned).

try declaring the arrazys globally, outside any function.

And its int main(), never void main()

#include <iostream>

const int size=85020;

int b[size];

char c[size];


float f[size];


int main()
{

   std::cin.get();
}

Edited 5 Years Ago by Ancient Dragon: n/a

>> still giving error after globally declaring the array

What is the error message? If you don't have enough memory and you're not allowed to use any of the workarounds suggested like the "new" command or vectors, then you have to go to a computer with more resources, shut down some other programs, or whatever. You can only do so much with the code itself. If the operating system or compiler or whatever refuses to give you the memory, you're out of luck.

Am i correct in thinking you have been given an assignment in which you need to create a large array(and you are presumably using the same compiler as your teacher or whoever gave you this task) and you can't use pointers or vectors?

Then it seems like an unusual assignment.:confused:

Well there you go. You are trying to drive on an interstate, freeway or autobahn with a Model T car built in 1910. You are using a 16-bit compiler that has very very limited memory and stack space. Sorry, but there is nothing you can do to fix your problem without switching to a modern 32-bit compiler or reducing the size of those arrays.

Edited 5 Years Ago by Ancient Dragon: n/a

Comments
Yes!
This article has been dead for over six months. Start a new discussion instead.