Monday, 15 March 2010

c - Confusion in the output -


I have just started my data type revised chapter, I am currently studying the concept of signed and unsigned character. My suspicion is that there is a limit of 128 to 127 in the signed room, then why are the code given below still running? Apart from this, the code given below is giving the Infinite O / P which I do not understand

  Main () {Four f; Printf ("\ n% d% c", ch, ch) for (ch = 0; ch & lt; = 255; ch ++); }   

Am I currently using the GCC 32-bit compiler? Can someone help me understand the O / P code given above?

 for  (ch = 0; ch & lt; = 255; ch ++)   

If ch is a signed character, then it will begin with 0 and increase will be 127. Then, on the next increment, it will be "wrap around" and -128. Using unsigned char :

  127 = 0x7f 128 = 0x80   

, but a Using signed four, 0x80 becomes -128.

Now it will run from ch -128 to 127. And since then, less than 255 of those values, it repeats until you stop the program ..

No comments:

Post a Comment