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 solutionChapter 10 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
- (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays so that a customer’s record can be accessed randomly by account number. Create the file by entering five customer records, with each record consisting of an integer account number (starting with account number 1000), a first name (maximum of 10 characters), a last name (maximum of 15 characters), and a double-precision number for the account balance. After the file is created, write a C++ program that requests a user-input account number and displays the corresponding name and account balance from the file.arrow_forwardc++problemarrow_forwardProgramming Language: C++ Create a variable val with value 6. Using a pointer variable, display the value 6.arrow_forward
- The occurrence of the pointer vanishing when it is rapidly moved is commonly referred to as submarining.arrow_forwardC++ Coding: ArraysTrue and False Code function definitions for eoNum() and output(): Both eoNum() and output() are recursive functions. output() stores the even/odd value in an array. Store 0 if the element in the data array is even and store 1 if the element in the data array is odd. eoNum() displays all the values in an array to the console.arrow_forwardC++ programmingarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning