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 (8th 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
- You can dereference a smart pointer with the * operator. True Falsearrow_forwardDescribe Operations on Pointer Variables.arrow_forwardC Program solve Pointer Arithmetic Write a program that accepts a string and print the reversed form of that string using a pointer ptr. Input: One line Containing String Sample Output: Enter a string: Test tseTarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning