Home > Uncategorized > array besar di c

array besar di c

waktu itu mau coba alokasikan array di c, ukuran 500an kali 35000an.

langsung crash, hehehe. coba pake cara lain

bikin array of pointer dulu, terus masing2 baru deh dialokasikan pakai malloc.

ini contoh programnya.

 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
int width=600, height=40000;
int* foo[width];
int i;
for(i=0;i<width;i++) {
foo[i]=malloc(sizeof(int)*height);
}

foo[width-1][height-1]=5;
printf(“%d\n”, foo[width-1][height-1]);

for(i=0;i<width;i++) {
free(foo[i]);
}

printf(“end\n”);
}

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment