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 31RQE
Program Plan Intro
Shared pointers:
- Shared pointers are used in managing the ownership of the dynamically allocated object.
- Shared pointers are used when there are one or more owners available for the objects that are allocated dynamically.
Example:
The below snippet illustrates the usage of the shared pointer that manages different object:
//usage of the shared pointer for the object stu1
shared_ptr<Student> stu1(new Student ());
//usage of the shared pointer for the object stu2
shared_ptr<Student> stu2(new Student ("George", 95));
Explanation:
In general in the above code, the execution is carried out by making two separate memory allocation:
- Allocate the control block
- Allocate memory for the object Student that needs to be managed.
When making separate allocation could incur significant overhead problems, in order to avoid the above problem the make shared function is used to efficiently allocate the memory.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In C, in order to do operations to the data being referenced by a pointer you would need to use the (*) operator, which is called ______________
operator.
c++ programming language
given the following variable declaration: double avg; write the required commands to declare a pointer, and then use it to display the value of the variable avg.
Shared pointers keep a count of all of the shared pointers that appear in the program code.
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
- (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_forwardUsing C++ Programming language: Given the following definitions: int num1=1, num2=2; int *ptr1=NULL, *ptr2=NULL; Write the following statements: Assign ptr1 to the address of num1. Assign ptr2 to the address of num2. Using pointer notation, write a statement that compares the values that the pointers "point" to to see which is larger. (There is more than one way to do this. You choose.)arrow_forwardWhat is a pointer? How do you dereference a pointer to get its stored value?arrow_forward
- In C programming: Write a main() function using the following requirements:• Define a SIZE constant (the value is irrelevant, but for testing, you may want to keep it small enough – no bigger than 5)• Create an array of course pointers using SIZE• Dynamically allocate each element of the array• Call inputAllCourses()• Call printAllCourses().arrow_forwardIN C PROGRAMMING LANGUAGE: Please write a pointer version of squeeze() named psqueeze(char *s, char c) which removes c from the string s.arrow_forwardWhat are smart pointers, and how do you use them? What are their functions?arrow_forward
- C++ code NB: Pointers must be usedarrow_forwardIN C PROGRAMMING LANGUAGE: Please write a pointer version of strncmp() named pstr_ncmp(char *s, char *t, int n) which compares the first n characters.arrow_forwardIN C LANGUAGE A drop shipping startup needs a system to manage sales orders. Create a Function that uses a Structure to manage company’s sales system. Use a Pointer to store n number of sales orders (where n is entered by the user) with the following information for each order: Order Number, Product Information, Quantity, Price, Customer Name, Customer Contact, Customer Address, Shipping Charges, Total Amount (Price + Shipping Charges). The function passes on order to a third-party supplier. Display all the orders to the supplier who then ships each order to the customer.arrow_forward
- C++ CODİNG. I want you to write some functions using given struct and please create a class. When you write functions you need to use pointers, ccreate linked list. struct node { char data; node *right; node *down; } First function has to Display all the rows starting with a specific character Second function Display all the columns starting with a specific character Third one Delete all the rows starting with a specific character. And also You need to use header file. You do not need to write main function, as i said before ı just want to functions.arrow_forwardWhich function does not return the pointer correctly?The code below calls the getline member function of cin to read a line of characters from cin into an array of characters up to a certain limit specified as the second parameter of the call.Your job is to find out if the pointer returned from the function can still be used by the caller of the function to access the memory that is pointed to by the pointer.char *getName() { char buf[80]; cout << "Enter your name: "; cin.getline(buf, 80); return buf;}char *getName() { char buf[80]; cout << "Enter your name: "; cin.getline(buf, 80); return buf;}char *getName() { char *buf = new char[80]; cout << "Enter your name: ";cin.getline(buf, 80); return buf;}None of thesechar getName(char buf, int size) { **cout << "Enter your name: ";cin.getline(buf, size);return buf;}arrow_forwardIf integer pointer aPtr is to point at a data item whose value may not change it must be declared as ... A. const int * const aPtr; B. int *aPtr; C. int *const aPtr; D. const int *aPtr;arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning