Posts

Showing posts from March 20, 2019

How exactly is this function an example of a char to int conversion?

Image
6 The book The C Programming Language by Kernighan and Ritchie, second edition states on page 43 in the chapter about Type Conversions : Another example of char to int conversion is the function lower , which maps a single character to lower case for the ASCII character set . If the character is not an upper case letter, lower returns returns it unchanged. /* lower: convert c to lower case; ASCII only */ int lower(int c) { if (c >= 'A' && c <= 'Z') return c + 'a' - 'A'; else return c; } It isn't mentioned explicitly in the text so I'd like to make sure I understand it correctly: The conversion happens when you call the lower function with a variable of type char , doesn't it? Especially, the expression c >= '