Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 10, Problem 34RQE
Program Plan Intro
Pointer:
Pointer, the name itself references the purpose of the pointer. Pointers point to a location in memory.
- Pointer is a special type of variable to store the address of the memory location, which can be accessed later.
- If an asterisk “*” operator is present before the variable, then that variable is referred as pointer variable.
- It is also called as dereferencing or indirection operator.
- Pointer is just a type of variable that stores the addresses of other variables.
- Using pointers, we can access the address of a variable; the data stored in that variable can be retrieved.
Syntax of pointer variable declaration:
<variable-type> *<variable-name>;
Example for pointer variable declaration:
//definition of pointer variable
int *ptrvar;
Where,
- “int” is the variable type.
- “* ptrvar” is the pointer variable name.
Pointer will allow the user to indirectly access and manipulate the data contents of the variable. A pointer variable will hold the address of the data contents.
Note:
- When the symbol “&” is placed prior the pointer variable, it will hold address of the pointer variable.
- When the symbol “*” is placed prior the pointer variable, it will hold the value of the pointer variable.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
None
Instructions:
In the code editor, you are provided with a main() function that asks the user for a string and passes this string and the size of this string to a function call of the function, preserveString().
This preserveString() function has the following description:
Return type - void
Name - preserveString
Parameters
The string
Length of the string
Description - this is a recursive function that prints the string repeatedly. Each time it prints the string, it excludes the last character of the string until only one character is left.
This preserveString() function has already been partially implemented. Your only task is to add the recursive case of this function.
Please Finish the code ASAP:
This is my current given code:
#include<stdio.h>#include<string.h>
#define STR_MAX_SIZE 100
void preserveString(char*, int);
int main(void) { char str[STR_MAX_SIZE];
printf("Enter string: "); fgets(str, STR_MAX_SIZE, stdin);
preserveString(str,…
In operator overloading, if you overload == as a nonmember function, you are allowed to pass one or
both objects as parameters
O True
False
Chapter 10 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 10.5 - Prob. 10.1CPCh. 10.5 - Write a statement defining a variable dPtr. The...Ch. 10.5 - List three uses of the symbol in C++.Ch. 10.5 - What is the output of the following program?...Ch. 10.5 - Rewrite the following loop so it uses pointer...Ch. 10.5 - Prob. 10.6CPCh. 10.5 - Assume pint is a pointer variable. For each of the...Ch. 10.5 - For each of the following variable definitions,...Ch. 10.10 - Assuming array is an array of ints, which of the...Ch. 10.10 - Give an example of the proper way to call the...
Ch. 10.10 - Complete the following program skeleton. When...Ch. 10.10 - Look at the following array definition: const int...Ch. 10.10 - Assume ip is a pointer to an int. Write a...Ch. 10.10 - Assume ip is a pointer to an int. Write a...Ch. 10.10 - Prob. 10.15CPCh. 10.10 - Prob. 10.16CPCh. 10.10 - Prob. 10.17CPCh. 10.12 - Prob. 10.18CPCh. 10.12 - Assume the following structure declaration exists...Ch. 10.12 - Prob. 10.20CPCh. 10 - Each byte in memory is assigned a unique _____Ch. 10 - The _____ operator can be used to determine a...Ch. 10 - Prob. 3RQECh. 10 - The _____ operator can be used to work with the...Ch. 10 - Prob. 5RQECh. 10 - Creating variables while a program is running is...Ch. 10 - Prob. 7RQECh. 10 - If the new operator cannot allocate the amount of...Ch. 10 - Prob. 9RQECh. 10 - When a program is finished with a chunk of...Ch. 10 - You should only use the delete operator to...Ch. 10 - What does the indirection operator do?Ch. 10 - Look at the following code. int X = 7; int ptr =...Ch. 10 - Name two different uses for the C++ operator.Ch. 10 - Prob. 15RQECh. 10 - Prob. 16RQECh. 10 - Prob. 17RQECh. 10 - What is the purpose of the new operator?Ch. 10 - What happens when a program uses the new operator...Ch. 10 - Prob. 20RQECh. 10 - Prob. 21RQECh. 10 - Prob. 22RQECh. 10 - Prob. 23RQECh. 10 - Prob. 24RQECh. 10 - Prob. 25RQECh. 10 - Prob. 26RQECh. 10 - What happens when a unique_ptr that is managing an...Ch. 10 - What does the get ( ) method of the unique_ptr...Ch. 10 - Prob. 29RQECh. 10 - Prob. 30RQECh. 10 - Prob. 31RQECh. 10 - Prob. 32RQECh. 10 - Consider the function void change(int p) { P = 20;...Ch. 10 - Prob. 34RQECh. 10 - Write a function whose prototype is void...Ch. 10 - Write a function void switchEnds(int array, int...Ch. 10 - Given the variable initializations int a[5] = {0,...Ch. 10 - Each of the following declarations and program...Ch. 10 - Prob. 39RQECh. 10 - Test Scores #1 Write a program that dynamically...Ch. 10 - Test Scores #2 Modify the program of Programming...Ch. 10 - Indirect Sorting Through Pointers #1 Consider a...Ch. 10 - Indirect Sorting Through Pointers #2 Write a...Ch. 10 - Pie a la Mode In statistics the mode of a set of...Ch. 10 - Median Function In statistics the median of a set...Ch. 10 - Movie Statistics Write a program that can be used...Ch. 10 - Days in Current Month Write a program that can...Ch. 10 - Age Write a program that asks for the users name...Ch. 10 - Prob. 10PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- in C++ mathematical functions languagearrow_forwardConsider the following function: void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?arrow_forwardWhat does the function f do? struct Point2D { double x; double y; struct Triangle { Point2D v1; Point2D v2; Point2D v3; }; void f(Triangle&t) { } int temp = 12.5; temp = t.v1.x; t.v1.x = t.v1.y; t.v1.y = temp; } int main () { Triangle mytri; mytri.v1.x = 1.0; mytri.v1.y = 22.5; f (mytri); Swaps values of x and y in vertex 1 of an argument of type Triangle Initializes value of x in vertex 1 of an argument of type Triangle Sets all x,y values in all vertices of an argument of type Triangle Swaps value of x in vertex 1 with value of x in vertex 2, for an argument of typearrow_forward
- Complete the following function using pass-by-reference: void findMax(int &max, int a) which assigns value ‘a’ to ‘max’ if a > max. Write a pseudo-code then implement a program in C language to find the maximum in a sequence of numbers using this function.arrow_forwardQ6: Write a program in C++ that contains overloaded functions with name OvOperation(). When the main program makes a call to OvOperation the program performs the following according to the arguments of the function call: OvOperation(): returns an int 0. OvOperation(float, float) returns the maximum between the arguments. OvOperation(int, int, int) returns the minimum value among the arguments. OvOperation(char) return the next ASCII character (e.g. OpOperation('a') returns 'bʻ).arrow_forwardCode Should Be In C++arrow_forward
- Q6: Write a program in C++ that contains overloaded functions with name OvOperation(). When the main program makes a call to OvOperation the program performs the following according to the arguments of the function call: • OvOperation(): returns an int 0. • OvOperation(float, float) returns the maximum between the arguments. • OvOperation(int, int, int) returns the minimum value among the arguments. OvOperation(char) return the next ASCII character (e.g. OpOperation('a') returns 'b'). int main () cout << Opoperation ( 'w' )<< endl << Opoperation () « endl; cout << OpOperation (1.1,0.5) << endl << Opoperation (4,-2,9); return 0;arrow_forwardImplement the following function: 1) Name: GenerateRandom 2) Parameters: a (int), b (int), N (int) 3) Job: Generate and display N random numbers in the range [a – b] including a and b. The function will display the random numbers, display their sum and return the average of all random numbers. The main() is provided. All you need is to implement the function GenerateRandom(). Note: Your output will be different because numbers are generated randomly. use C++arrow_forwardhe function drawFractalLine is recursive. Write a script that draws the Koch snowflake. Define a function main that will draw a Koch snowflake with the following parameters when the program is run: Width = 200 Height = 200 Size = 150 Level = 4arrow_forward
- in C++ Write a function that allows you to modify a Planet in the SolarSystem class. You can choose to pass a Planet into this function, or have the function prompt for planet information. Either way, you need to be able to specify the Planet at a specific index to be modified. This is an example of how it could potentially look in the main: // code that declared a SolarSystem the_system// and assigned planetsPlanet p("X", 2000, 4000);int index = 2;the_system.changePlanet(p, index);arrow_forwardProblem 1: Recursion to Generator You worked with these last homework. For this homework, you'll write the tail recursion, while, and generator. This is a reminder that in the starter code, we are providing you with the regular recursion code, and the functions you must implement must utilize tail recursion, a while loop, or a generator as specified. In your starter code, function names will end in _t, _w, or _g if the function needs to be implemented using tail recursion, a while loop, or a generator, respectively. Review the lecture slides to learn more about generators. p(0) p(n) = 10000 = p(n-1) + 0.02p(n − 1) c(1) = 9 c(n) = 9c(n-1) + 10-1 — c(n − 1) d(0) = 1 d(n) = 3d(n-1) + 1 Programming Problem 1: Recursion to Generators • For reach function you'll write the tail recursive form, while, and generator. • We have added the signature to help you-in particular, c(n) requres two accumula- tors. (1) (2) (3) (4) (5) (6) (7)arrow_forwardFill in the c code for the question below: Define the function: void deleteAtV1(int num[], int *count , int pos); //The function deletes the item at pos For example: Test Result int num[10]={4,5,1,2,8}; int coun=5; deleteAtV1(num,&count,2); display(num,count); 4528 code: void display(int num[], int size){ int i; for(i=0;i<size; i++) printf("%d", num[i]);} // Fill up this missing code to delete [2} in the arrayarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning