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 language and using pointersarrow_forwardc++problemarrow_forward
- C 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_forwardWhen you move the pointer too quickly, a phenomena known as "submarining" might take place, in which the pointer vanishes.arrow_forwardThe occurrence of the pointer vanishing when it is rapidly moved is commonly referred to as submarining.arrow_forward
- Explain the general syntax to declare a pointer variable.arrow_forwardUsing C++ programming language: Assume intptr is a pointer to an int. Write a statement that will dynamically allocate an array of 100 integers and store its address in intptr. Also, write a statement that will free the memory allocated in the statement you just wrote.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_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning