c - The value of EOF different for different specifiers? -


this question has answer here:

im using codeblocks.

below program in c:

/*to find value of eof ( end of file ) number */  #include<stdio.h> int main() {      printf("the eof value is: %d %5ld",eof, eof);     /*when eof specified in %d specifier giving value -1, if           given %ld number  4294967295 printed on console?*/     return 0; } 

as said in comments of program:

  • when eof specified in %d specifier giving value -1, if given %ld number 4294967295 printed on console?

i'm using 64 bit linux os on hp. [ if matters compiler assigning memory ints, floats , longs ]

it's defined (-1), it's implicitly int. correctly shown -1 when printed using %d. however, passing int printf() when long expected invokes undefined behavior.

what probably happens, system uses 2's complement, 32-bit int , 64-bit long , bit pattern (int)-1 same corresponds (long)4294967295.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -