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 character (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
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Double Pointer (Pointer to Pointer) in C
- Pointer to an Array | Array Pointer
- What is a Pointer to a Null pointer
- Java Program to Count the Total Number of Vowels and Consonants in a String
- Count the pairs of vowels in the given string
- Count substrings that contain all vowels | SET 2
- Minimum cost to convert given string to consist of only vowels
- Sum of array using pointer arithmetic
- Delete multiple occurrences of key in Linked list using double pointer
- Trie Data Structure using smart pointer and OOP in C++
- Pointer vs Array in C
- Declare a C/C++ function returning pointer to array of integer pointers
- 'this' pointer in C++
- Type of 'this' pointer in C++
- Multidimensional Pointer Arithmetic in C/C++
- How to write C functions that modify head pointer of a Linked List?
- Function Pointer in C
- Opaque Pointer
- Passing by pointer Vs Passing by Reference in C++
- Null Pointer Exception In Java
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.
Improved By : shubham_singh