C# Program to Count Vowels in Character Array Using Pointers

Sometimes we get frustrated if we do not get the information we need in some articles. But this article has all the information you need when you read C# Program to Count Vowels in Character Array Using Pointers. Read patiently and understand.

C# Program to Count Vowels in Character Array Using Pointers

C# Program to Count Vowels in Character Array Using Pointers

//C# program to count vowels from character array using pointers.

using System;

class UnsafeEx
{
    static unsafe void Main(string[] args)
    {
        int loop = 0;
        int countVowels=0;

        char[] str = { 'i','n','c','l','u','d','e','h','e','l','p'};
        
        fixed(char *ptr = str)
        for (loop = 0; loop<str.Length; loop++)
        {
            if ((*(ptr + loop) == 'a') || (*(ptr + loop) == 'e') || (*(ptr + loop) == 'i') || (*(ptr + loop) == 'o') || (*(ptr + loop) == 'u'))
                countVowels++;
        }
        Console.WriteLine("Total Vowels are: "+countVowels);
    }
}
Total Vowels are: 4
Press any key to continue . . .

Final Words

We hope the C# Program to Count Vowels in Character Array Using Pointers article helped you in some way. And let us know if you have any doubts. Thanks

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment