Possible Duplicate:
c dynamic memory allocation and sizeof()
I am trying to find the cache block by keeping a huge block of 16 MiB and by trying to access different elements each time to find the time. I just can't write the length of the array.
How can I write a for loop to iterate over the array. I need the length of the array; how can I find that? I have tried sizeof(a)/sizeof(a[0])
but this doesn't work or I am doing something wrong because my assignment sheet tells me it can hold 4 million int
's..
register *a;
a = malloc(16777216);
int i;
for (i = 0; i < sizeof(a)/sizeof(a[0]); i = i + 1) {
printf("\ni = %d", i);
}
This only prints i = 0 i = 1.