سؤال

in my C program, when I am taking an array like this

int a[100000][100000];

I am getting segmentation fault. Now if I am using array of size less than 1000 * 1000 , like this

int a[1000][1000];

I am not getting any problem.In my program I need to use a 10^5 * 10^5 array. What should I do to fix it .

هل كانت مفيدة؟

المحلول

Dynamically allocate it with malloc. By declaring it statically you use the stack, which has a maximum size that the heap (used in dynamic allocations) does not.

int *pointer = malloc (sizeof (*pointer) * (100000*100000));

Then, to access it, use indices to represent the x and y coordinates.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top