if(some_filepointer != NULL) { // do this }

increment the file pointer? does the evaluation move the pointer to the next character in the file because the if condition read from the file?


1 Answer 1


Does the code above increment some_filepointer in the code above? No. All it does is check whether the pointer is actually pointing as something other than NULL. It won't change the pointer in any way.

HOWEVER, a common practice is to actually change a pointer and simultaneously test the result of that change. For example:

if( fseek(inptr, padding, SEEK_CUR) == 0 ) 
    printf("fseek succeeded.\n");

This will cause the file pointer inptr to move to a different location in the file that it points at. If the fseek() succeeds, the pointer would be changed and the function would return 0.

The only time a pointer is changed as part of an IF condition is when there is something actually acting on the pointer, such as a function or an operator. A logical compare will not change the pointer. If it fails, it would return a non-zero value. I couldn't find documentation on what happens to the pointer, but I would assume it is unreliable at that point.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .