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

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: