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_forwardIn C programming language: Write a function that takes 3 int arguments and returns the largest of the 3.arrow_forwardPointer 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
- Programming Language: C++ Create a variable val with value 6. Using a pointer variable, display the value 6.arrow_forwardMonth Day Calculator in C Using basic concepts of Pointers and Structures (Pointers and Multi-dimensional arrays), create a C program that calculates the month's day from a given year and year's day. Use pointers for the month and month's day variables. Don't forget to add proper errors handling in your program. - Follow the instructions below for handling error. - Invalid Input- Invalid year- Invalid year day Modify the provided monthAndDay.c class file to receive the parameters in the way and also print the proper formatted output. Example: # ./month_day <year> <yearday> # Example for Feb 2nd, 2019:\$ ./month-day 2019 33Feb 02, 2019 class- monthAndDay.c - #include <stdio.h> /* monthAndDay function's prototype*/void monthAndDay(int year, int yearday, int *pmonth, int *pday); int main() {return 0;}arrow_forwardIn C language, write a program to input two integers x,y and add both the integers using pointers and display the result in the output. The assignment will be rejected if the numbers are added without the use of pointers.arrow_forward
- Submarining is a phenomenon that occurs when the pointer disappears when you move it too rapidly.arrow_forwardShared pointers keep a count of all of the shared pointers that appear in the program code. True Falsearrow_forwardYou can dereference a smart pointer with the * operator. True Falsearrow_forward
- Describe Operations on Pointer Variables.arrow_forwardWhat is the purpose of a pointer?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