well my friend compile and run this tiny code and see what happens for yourself , i found this code from a book that am reading right now and modified it out of curiousty and BOOM !!! c assigns a negative ASCII value to some symbols , please somenoe explain to me if there is such thing as a negative ASSCII value . If the answer is NO why is c assighning a neg value to those symbols in this particular program . Thanx like always
for (ch = 'A'; ch <= 'Z'; ch--)
printf("\aASCII value for %c is %d.\n", ch, ch);
>c assigns a negative ASCII value to some symbols
No, C assigns a negative integral value to the variable and the system happens to have a printable representation for that value. It doesn't mean that it's ASCII.
>I expect that in your system char == unsigned char.
No, if that were the case the the loop would terminate after ch reached 0. This is because the value would roll around to the largest unsigned value for char. That value is larger than the ASCII value for 'Z', so the loop would break successfully. The fact that the OP is seeing negative values is an indicator that the default type for char is signed, not unsigned.
>If you know about it, it can be very useful.
Very useful for breaking things.
>for ( signed char x=1; x != 0; ++x )
This is undefined behavior. You're overflowing a signed integral type.
Is there any symbol for which there is no ascii value and c prints a -ve garbage value for that. I am getting the value -69 wheneevr I am trying to print the ascii value of the symbol ">>". Please treat the symbol within quotes as a single symbol.I am sending the file test.txt containing the particular symbol.
there are a lot of unprintable characters between 0 and 255. Look at any ascii chart such as this one and you see that printable chars start with decimal value 32 (a space) and ends in decimal value 126 the tilda ~. Values above and below those two values may or may not be pritable, depending on the code, or language, set.
So if you try to print one of those non-printable characters to a file in its binary form (which is probably what happened in the text file you posted) all you will most likely see in the file is a funny-looking square when displayed with Notepad. Other text editors may display them as some other symbol or not at all.