Hi,
I get a segmentation fault whenever I try to dereference a pointer in a for loop. What is the reason and is there a solution to this problem?
Here is some sample code that exhibits the problem:
note for above code, I could have *pointer = 0; in the for loop and I'd still get the same error.Code:#include <stdio.h> #define LENGTH 5 int main() { int* pointer = 0; for (int i = 0; i < LENGTH; i++) { *pointer = (*pointer) + 1; printf("%d", *pointer); } printf("\n"); }