Pre-requisite: Pointers in C++
Given a string of lowercase english alphabets. The task is to count number of vowels present in a string using pointers
Input : str = "geeks" Output : 2 Input : str = "geeksforgeeks" Output : 5
- Initialize the string using a character array.
- Create a character pointer and initialize it with the first element in array of charcter (string).
- Create a counter to count vowels.
- Iterate the loop till character pointer find ‘\0’ null character, and as soon as null character encounter, stop the loop.
- Check whether any vowel is present or not while iterating the pointer, if vowel found increment the count.
- Print the count.
Below is the implementation of the above approach:
Vowels in above string: 5
- Program to count occurrence of a given character in a string
- Double Pointer (Pointer to Pointer) in C
- Count palindromic characteristics of a String
- Count occurrences of a word in string
- Count occurrences of a sub-string with one variable character
- Count of cyclic permutations having XOR with other binary string as 0
- Longest Ordered Subsequence of Vowels
- Longest substring having K distinct vowels
- 'this' pointer in C++
- Function Pointer in C
- Opaque Pointer
- A C/C++ Pointer Puzzle
- Pointer to an Array | Array Pointer
- void pointer in C / C++
- NULL pointer in C
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.