+ 1

What does #define CHAR_TO_INDEX(c) ((int)c-(int)'a') mean?

17th Mar 2017, 6:48 AM
Anurag Lahon
Anurag Lahon - avatar
4 Answers
+ 2
look up for ASCII table, here you will see distance between a and n equals 13 :)
17th Mar 2017, 8:26 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
It is a macro definition CHAR_TO_INDEX(c) accepting a character argument. (int)c - returns the index of character represented by c (int)'a' - returns the index of character 'a' hence ((int)c-(int)'a') - returns the distance between value in c and letter 'a' #include <iostream> #define CHAR_TO_INDEX(c) ((int)c - (int)'a') using namespace std; int main (){ cout<<CHAR_TO_INDEX('n'); //returns 13 }
17th Mar 2017, 8:21 AM
ą¤¦ą„‡ą¤µą„‡ą¤‚ą¤¦ą„ą¤° ą¤®ą¤¹ą¤¾ą¤œą¤Ø (Devender)
ą¤¦ą„‡ą¤µą„‡ą¤‚ą¤¦ą„ą¤° ą¤®ą¤¹ą¤¾ą¤œą¤Ø (Devender) - avatar
0
how does it returns 13?
17th Mar 2017, 8:23 AM
Anurag Lahon
Anurag Lahon - avatar
0
thanx
17th Mar 2017, 8:27 AM
Anurag Lahon
Anurag Lahon - avatar