why is variable C is in int form when it is used to print characters | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 1

why is variable C is in int form when it is used to print characters

the variable which is used in the while loop

27th Jan 2019, 1:38 PM
Namith N
Namith N - avatar
3 Respostas
+ 3
I don't know what code you are talking about, but yeah, you can use characters as if they were numbers (their ascii code). For example: char i; for (i='a'; i <='z'; i++) { printf("%c", i); }
28th Jan 2019, 10:34 AM
Zen - avatar
+ 1
Char and int are almost interchangeable. Char is intended to contain characters. Characters include the printable characters and control characters like tab, esc, cr, and of. Originally the ascii character set was all the numbers that can be represented in 7 bits. The 8th bit was used for parity checking when transmitting data. The 8th bit is now used to identify an extended character set which is usually line drawing or other special characters. Since older computers recognized characters as 8bit, and int as an 8bit number, the representation of a char was an unsigned 8bit int. Because of this, char and unsigned int can be interchangeable. Its important to remember that using a signed int as a char may give an incorrect result as the sign bit will most likely be dropped when converting a signed int to a char. This will have the effect of shifting the special character set down into the standard character set. A char is an unsigned 8 bit number that can be used as an unsigned int, or as a character.
1st Feb 2019, 4:41 AM
Roger Greenlaw
Why w?
20th Jan 2020, 3:35 PM