> For the complete documentation index, see [llms.txt](https://nitinranganath.gitbook.io/data-structures/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nitinranganath.gitbook.io/data-structures/strings/permutations-of-a-string.md).

# Permutations of a String

### Backtracking C Function :

```c
void permutate(char a[], int l, int r) {

    if (l==r) {
        // Print the string when indexes match
        printf("%s\n", a);
    } else {
        for (int i = l; i <= r; i++) {
            // Swap to get permutation
            swap(&a[l], &a[i]);
            // Recursive call
            permutate(a, l+1, r);
            // Backtrack
            swap(&a[l], &a[i]);
        }
    }

}

```

Contributed by Nitin Ranganath
