-2
for(int i = 0;i < length; i++){
        count[string[i] - 'a']++;
    }

I have seen many people use this code to count the number of occurrences of each letter in a string.Would like to know how this code does that.

1 Answers1

0

Every char is a number in C++. So count[i] stores the number of occurences of i'th letter.

Murat Akburak
  • 51
  • 1
  • 1
  • 12