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();

}

Recommended Answers

All 16 Replies

frogboy @ :( still having problem by reading your thread

>> still having problem by reading your thread

What problems? Post a code snippet.

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

can you use vectors?

i can only use loops, one d array or 2 dimensional array

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

still giving error after globally declaring the array

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

what compiler and operating system are you using?

I'm using Window Vista 32 Bit

Compiler : Turbo C++ Version 3.0

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.

commented: Yes! +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.