I'm writing a program in which I fscanf a file and write to the same memory  address repeatedly. I tried the following:FILE *f = fopen(fname, r);int* num;while(fscanf(f, %d,, num) != EOF) {    printf(%d\n, *num);} which, when I run it, produces Bus Error 10, which means to the best of my understanding that I'm trying to write to an unauthorized address.The following works, however:FILE *f = fopen(fname, r);int num;while(fscanf(f, %d,, &num) != EOF){    printf(%d\n, num);}  Both compile fine, as I'd expect. What I don't understand is why I can write directly to a memory address but not a pointer to that address. And if they're not the same, why does it compile?
What's the difference between writing to the memory address of a declared int and writing directly to an int*?
c;pointers
In your first attempt, num is an uninitialized pointer, and fscanf (which is expecting a pointer) is attempting to store an int through that pointer. But num is probably pointing into protected memory (probably location 0), since it has not been initialized to point anywhere.In your second attempt, num is an int, and memory has been allocated for it by its definition int num;. Then, fscanf is given a pointer to that memory location, and successfully stores the int, because the memory location is valid (which it was not in your first attempt).