Initializing pointers always necessary?
I've been encountering info lately that seems to suggest that *all* pointers in C code should always be initialized. Does anyone know if this is always true/necessary?
I'm also confused about *how* to correctly initialize pointers; I've searched for examples, and they vary from recommending that pointers be initialized to NULL, to setting them to the address of a variable. Is one or the other technique always correct, or will it depend on the application?
For my own code, the only pointers I have are FILE pointers. e.g.:
FILE *fid1, *fid2;
When I'm done using them, I do fclose(fid1); and fclose(fid2);
My questions:
a) for my FILE pointers, how do I correctly initialize these?
b) Is there anything different/additional that I need to do when I'm done using these initialized pointers, beyond calling fclose( )? I read in one place that you're supposed to set the pointers to 0 after calling fclose( ), but am not sure if this is true, and if true, I'm wondering about the correct syntax for this.
I should note that my current code is giving weird output, e.g. variables that should have values have NAN or nonsense values; I'm thinking that possibly my noninitialized pointers *may* have something to do with this. (All of my other regular variables are initialized to 0 or 0.0, depending on type).
Thanks for your input.