C++ Programming Code Examples C++ > Strings Code Examples Find Frequency of Characters in a C-style String Find Frequency of Characters in a C-style String In this example, frequency of occurrence of a character is checked for both (String object and C-style string). In this example, frequency of characters in a string object is computed. To do this, size() function is used to find the length of a string object. Then, the for loop is iterated until the end of the string. In each iteration, occurrence of character is checked and if found, the value of count is incremented by 1. #include <iostream> using namespace std; int main() { char c[] = "C++ Programming Language | Happy Codings :)", check = 'm'; int count = 0; for(int i = 0; c[i] != '\0'; ++i) { if(check == c[i]) ++count; } cout << "Frequency of " << check << " = " << count; return 0; }