J
joint52
Hello
This seems to work in my system, until variable 'i' reaches 15985, then
the program crashes.
My question is, why won't it crash sooner? How does it work?
And why am I able to set the value of rowptr[0][5100]?
Thanks
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int nrows = 5, ncols = 10;
int row, i;
int **rowptr;
rowptr = malloc(nrows * sizeof(int *));
for (row = 0; row < nrows; row++)
rowptr[row] = malloc(ncols * sizeof(int));
rowptr[0][5100] = 4;
for (i = 0; i < 30000; i++) {
printf("%d %d\n", i, rowptr[0]);
}
printf("%d\n", rowptr[0][5100]);
return 0;
}
This seems to work in my system, until variable 'i' reaches 15985, then
the program crashes.
My question is, why won't it crash sooner? How does it work?
And why am I able to set the value of rowptr[0][5100]?
Thanks
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int nrows = 5, ncols = 10;
int row, i;
int **rowptr;
rowptr = malloc(nrows * sizeof(int *));
for (row = 0; row < nrows; row++)
rowptr[row] = malloc(ncols * sizeof(int));
rowptr[0][5100] = 4;
for (i = 0; i < 30000; i++) {
printf("%d %d\n", i, rowptr[0]);
}
printf("%d\n", rowptr[0][5100]);
return 0;
}