
Concept explainers
Explanation of Solution
Use of pointers to pass C-string argument:
In C++, for passing C-string argument the pointers are extremely useful. Each letter is passed through the pointer parameter variable. It will read until the null character, are part of the string.
Example program:
Consider the example that defines a function that uses a pointer to count the number of times a particular letter appears in a C-string is as follows:
//Header files
#include<iostream>
using namespace std;
//function prototype
int count(char*, char c);
// Define Main function
int main()
{
//Declare the constant variable
const int S = 20;
// Declare the variables as char type
char str[S], l;
//Get the input string from the user
cout << "Enter the string: ";
cin.getline(str, S);
//Get the letter from the user
cout << "Enter a letter: ";
cin >> l;
//call the function
cout << "The total number of times the " << ...

Want to see the full answer?
Check out a sample textbook solution
Chapter 10 Solutions
Starting Out with C++ from Control Structures to Objects Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage




