+ 1

What's the output, printf("%c %c",87,599); ? Please Explain!

the question is about basic concepts in C language

25th Jan 2019, 2:21 PM
Shekhar Srivastava
Shekhar Srivastava - avatar
5 odpowiedzi
+ 5
The code playground have the answer.
25th Jan 2019, 2:31 PM
JTLZ
0
%d expect a double floating point number, so output should be "87 599"
25th Jan 2019, 2:41 PM
Seb TheS
Seb TheS - avatar
0
the question was wrong earlier.. sorry
25th Jan 2019, 2:44 PM
Shekhar Srivastava
Shekhar Srivastava - avatar
0
It seems that characters are integers with a Batman suit, when integer i are converted to characters c, it returns the character from a builtin sequence of characters from the index i. (87 & 599)
25th Jan 2019, 3:02 PM
Seb TheS
Seb TheS - avatar
0
The output is "W W". The reason why those different integers give the same character is that the size of a char is 1 byte while it is 4 bytes for int, so an int with non-zero bytes outside of the first byte ends up truncated when cast into a char. So 599, which is 0x00000257 as an int, becomes 0x57 (ie 87) as a char, which is the ascii code for 'W'. https://code.sololearn.com/cWYn6mDK6eai/?ref=app
25th Jan 2019, 3:26 PM
Zen
Zen - avatar