VOOZH about

URL: https://www.geeksforgeeks.org/dsa/c-string-anagram/

⇱ String Anagram in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

String Anagram in C

Last Updated : 23 Jul, 2025

An anagram of a string is another string can be formed by the rearrangement of the same set of characters. In this article, we will learn how to check whether two strings are anagrams of each other in the C.

The simplest method to check whether two strings are anagrams of each other is by counting frequency of each character in both the strings and checking whether all characters have same count or not. Let’s take a look at an example:


Output
Anagrams

Note: If the input strings contain a larger set of characters, such as Unicode characters, using an array for frequency count may not be feasible.

There are also a few other methods in C to check whether two strings are anagrams of each other. Some of them are as follows:

Using Sorting

Sorting two anagram strings using qsort() will arrange their characters in the same order making both strings identical. The strcmp() function can be then used to check whether the two strings are identical or not.


Output
Not Anagrams

Using Optimized Frequency Counting

The frequency counting method can be optimized to use a single frequency array instead of two by counting the frequencies of both strings within the same array. Also, if the length of the strings is not same, they cannot be anagram.


Output
Anagrams
Comment