+ 1
What does #define CHAR_TO_INDEX(c) ((int)c-(int)'a') mean?
4 Answers
+ 2
look up for ASCII table, here you will see distance between a and n equals 13 :)
+ 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
}
0
how does it returns 13?
0
thanx