Hi,
I need help with this program . I am doing something wrong with pointer addition.
Getting a seg fault after i = 3 and gdb says each iternation is incrementing the pointer 10MB instead of 2MB.Code:/* program allocates 16 MB of memory on heap and writes to every 2MB interval*/ #include <stdio.h> #include <stdlib.h> #include <assert.h> #define INTERVAL (2UL * 1024 *1024) /* 2MB interval*/ int main(int argc, char *argv[]) { unsigned long p = malloc(atoi(argv[1])); assert(p); int i = 0; unsigned long interval = INTERVAL; int number_of_chunks = (atoi(argv[1])/INTERVAL); for(i = 0; i < number_of_chunks; i++){ p[i *INTERVAL] = (char) 1; /* write 1 at start location of each chunk */ } free(p); return 0; }